loop not displaying posts on custom template page

Make a copy of press.php and rename it to home.php. The page you selected “Press” to be the designated page for your posts in the dashboard under, Settings > Reading > Posts Page: [Press] …now falls under the control of the template hierarchy as listed by Milo. First WordPress will look for the existence of … Read more

next_posts_link not working in custom loop

only just use echo and get_ <?php $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 1 ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { $i = 0; while ($my_query->have_posts()) : $my_query->the_post(); if($i % 2 == 0) { ?> <div class=”row”><?php } ?> <div class=”col-md-6″> <div class=”overview”> <!– Post details here –> … Read more

Fastest way to loop through all posts?

“The Loop” is just a name given to the while (have_posts()): the_post(); loop used to iterate over an array of posts returned by WP_Query(). The other function used for querying posts is the get_posts() function, which returns a simple (non-extended) array which you can loop through with a foreach loop. I don’t think it matters … Read more

Specific Loop For 2 Within Each

i use this code in my portfolio http://pocketapps.co/ <?php $args = array( //your argument code ); query_posts($args);?> <ul> <?php $ls=0; while ( have_posts() ) : the_post(); ?> <?php if($ls%2==0): echo ‘</li><li>’; endif; ?> <div class=”app”> //your code here </div> <?php $ls++; endwhile; wp_reset_query(); ?> </ul>

Is there any need to use both wp_reset_postdata and wp_reset_query together?

There’s no need to use them both. You should only use wp_reset_query(), if you modified query with query_posts() (which you should avoid). This function also call wp_reset_postdata() – http://core.trac.wordpress.org/browser/tags/3.4.1/wp-includes/query.php#L95 So it’s better to use wp_reset_postdata() after running separate query.

First post of each category

It’s not possible to get one posts per category with one simple query, and even a complex query will take more time than 3 separate query. So, if you want simplest, then this is the solution – $cats = array(‘lifestyle’, ‘fashion’, ‘beauty’); $exclude_posts = array(); foreach( $cats as $cat ) { // build query argument … Read more

get_the_content not working in loop?

echo $post->post_content; will echo your post content. Keep in mind though, it’s raw out of the database (same as get_the_content()). If you want to apply the same filters that the_content() receives, follow the instructions in the codex: <?php $content = apply_filters(‘the_content’, $content); $content = str_replace(‘]]>’, ‘]]>’, $content); ?>

Pagination adding extra posts only on page 2

Here’s a suggestion for a general way to support different number of posts on the home page than on the other paginated pages. We should use the main query instead of sub-queries, if possible. Formula It seems to make sense to take the offset for paginated pages as: offset_op = ( paged – 1 ) … Read more