• I’ve set up a WordPress child theme and I’m modifying it to have a featured post area above my nav bar. This should show the featured image and headline from one post which I have selected in the admin section to be the day’s featured post. And, the post should not appear a second time, with the rest of the blog posts on the index page.

    I need a way to query the WP database and pull out the one post I’ve selected to be featured.

    What’s a good strategy? For example, is there a way to use post meta data for this purpose?

    Thanks very much in advance to all for any info!

Viewing 1 replies (of 1 total)
  • Thread Starter vikr

    (@vikr)

    I found it. I make the post sticky. To get the post, I use:

    <?php $post = get_post( $sticky_post_id ); ?>

    To keep it from printing in the main loop, I add this to the child theme’s functions.php file:

    function exclude_sticky( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set('post__not_in', get_option('sticky_posts'));
        }
    }
    
    add_action('pre_get_posts', 'exclude_sticky');
Viewing 1 replies (of 1 total)
  • The topic ‘Need Strategy: Post to Appear in Featured Area but Not Elsewhere on Index Page’ is closed to new replies.