Quantcast
Channel: Exclude only first post from one category from the latest posts feed, wordpress - Stack Overflow
Viewing all articles
Browse latest Browse all 7

Answer by Sumith Harshan for Exclude only first post from one category from the latest posts feed, wordpress

$
0
0

Method - 1

$cat_posts = new WP_Query('posts_per_page=1&cat=2'); //first 1 posts
while($cat_posts->have_posts()) { 
   $cat_posts->the_post(); 
   $do_not_duplicate[] = $post->ID;
}

//Then check this if exist in an array before display the posts as following.
 if (have_posts()) {
    while (have_posts()) {

    if (in_array($post->ID, $do_not_duplicate)) continue; // check if exist first post

     the_post_thumbnail('medium-thumb'); 

         the_title();

    } // end while
}

Method - 2

query_posts('posts_per_page=6&offset=1');
if ( have_posts() ) : while ( have_posts() ) : the_post();

This query is telling the loop to only display 5 posts which follow the most recent first post. The important part in this code is “offset” and this magic word is doing the whole thing.

More details from Here


Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>