Quantcast
Channel: Advanced – WP First Aid
Viewing all articles
Browse latest Browse all 3

Featured Image on the Post’s First Page Only

$
0
0

Did you know, by default, using a featured image on a post that is broken down into parts will display that featured images on each page/part of that post? For most themes this is the case … but what if you don’t want the featured image on each part of the post? That’s what we’re talking about here …

First off, there are a couple of things that need to happen. The theme is providing support for featured images (in posts, pages, etc.); and, the post has been broken down into parts (or pages) using the WordPress core <!–nextpage–> marker and the wp_link_pages() function.

Here’s the basics, as it applies to post templates (similar code could be used in page templates), such as index.php, single.php, etc.

You’re going to need a callback function:

/**
 * Post Is Paged
 *
 * @param array $haystack the body classes.
 *
 * @return bool|int
 */
function post_is_paged( $haystack ) {
	$needle = 'paged';

	return ( strpos( $haystack, $needle ) );
}

The callback function will be used here:

$post_is_paged = array_filter( get_body_class(), 'post_is_paged' );

Then you can use a conditional check on the $post_is_paged variable such as this:

if ( ! $post_is_paged ) {
	/** Create output to be displayed on the first page. */
} else {
	/** Create output for the second (or later) page of the post. */
}

That’s it … although I’m sure it could be better written, it does work; and, it will be part of the next theme I publish.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles



Latest Images