Get Ancestor featured image

Given this hierarchy: Page 1 Page 2 Page 3 Page 4 This line, where $post represents Page 4: $parents = get_post_ancestors( $post->ID ); Will return 3 IDs, for these pages, in this order: Page 3 Page 2 Page 1 So this line: $id = ($parents) ? $parents[count($parents)-1]: $post->ID; Is the equivalent of: $id = ($parents) … Read more

Featured Image VS Post_thumbnail — has_post_thumbnail lies?

In your Custom Post Type, do you setup_postdata( $post ) in your custom Loop? If not, has_post_thumbnail() might not be defined/available? EDIT: Try adding: setup_postdata( $post ); Right before: $loop->the_post(); And then see if has_post_thumbnail() returns true? Or, try passing the $post->ID to your call to has_post_thumbnail()? has_post_thumbnail( $post->ID );

How to display thumbnail + tags + title of a child page?

Assuming that you’ve enabled support for both post thumbnails and post tags for static Pages, I would use WP_Query() to build your query, and do something like the following: global $post; $child_pages_query_args = array( ‘post_type’ => ‘page’, ‘post_parent’ => $post->ID, ‘orderby’ => ‘menu_order’ ); $child_pages = new WP_Query( $child_pages_query_args ); if ( $child_pages->have_posts() ) : … Read more

Show featured image in sidebar

You can get the Post Thumbnail by get_the_post_thumbnail( ). Inside your widget add the following code: global $post; if ( has_post_thumbnail( $post->ID ) ) echo get_the_post_thumbnail( $post->ID, ‘your-image-size’ ); If there is a Featured Image, it will be shown.

How to use wp_get_attachment_metadata for thumbnails

The structure would be something like this. Check if you have a thumbnail Get the meta Add the meta data for w/h/file Then render the image if ( has_post_thumbnail() ) : // check if the post has a Post Thumbnail assigned to it. $upload_dir = wp_upload_dir(); $size=”full”; $post_thumbnail_id = get_post_thumbnail_id( $post_id ); $post_thumbnail_meta = wp_get_attachment_metadata … Read more

Conditional to grab parent page thumbnail URL

<?php $id = $post->ID; if( ! has_post_thumbnail( $id ) ) { // the current page has no feature image // so we’ll see if a) it has a parent and b) the parent has a featured image $ancestors = get_ancestors( $post->ID, ‘page’ ); $parent_id = $ancestors[0]; if( has_post_thumbnail( $parent_id ) ) { // we’ll use … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)