Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I skip the first post in WordPress?

Tags:

php

wordpress

How can I skip the first post in WordPress?

<?php
$recentPosts = new WP_Query();
$recentPosts->query(array('showposts' => 6,'post_type' =>array('stiri')));
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
like image 698
Batman Avatar asked Jul 28 '12 01:07

Batman


People also ask

How do I hide the first post on WordPress?

add_action( 'pre_get_posts' , 'wpsites_exclude_latest_post' , 1 ); This code will exclude the latest post from displaying on your home page loop. The offset is set to one, so only the first post will be hidden.

How do I exclude a post in WordPress?

To Exclude a Page From WordPress Search Results Excluding a page is done the same way you exclude a post. Go to your list of pages and click the “Edit” link for the post you would like to exclude. Scroll down to the bottom right of the post. Check the box for “Exclude from Search Results.”


1 Answers

Use the offset parameter:

<?php
$recentPosts = new WP_Query( 'offset=1' ) );
$recentPosts->query(array('showposts' => 6,'post_type' =>array('stiri')));
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
like image 165
João Mosmann Avatar answered Oct 12 '22 02:10

João Mosmann