Remove the_content From Loop

I don’t see anything that would cause the_content() to display in your code. Chances are, the template file you are editing is NOT the one being used on the page/archive you are checking. Add this to the top of your template files… <!– Template: <?php echo __file__; ?> –> Now, in your web browser view … Read more

Loop not showing up on page template

Firstly, use WP_query instead of query_posts: Secondly, for (static) pages use the variable ‘page’ (not ‘paged’). $my_query = new WP_query( ‘post_type=post&posts_per_page=5&paged=’ .get_query_var(‘page’) ); if ( $my_query->have_posts() ) while( $my_query->have_posts() ) : $my_query->the_post(); the_title(); endwhile;

Categories and page filtering with pre_get_posts

Please Consider this snippets of code. <?php $myarticles = new WP_Query( ‘post_type=myarticles&orderby=date&order=DESC&cat=4’ ); while ($myarticles->have_posts()) : $myarticles->the_post(); $postTitle = get_the_title(); $postid = get_the_id(); $postContent = get_the_content(); ?> <li><p><?php echo $postTitle; ?></p> <a href=”#”><?php the_post_thumbnail(array(219,143)); ?></a> <p><?php echo $postContent; ?></p> </li> <?php endwhile; ?>

Noob Loop Question

If you want to check the number of posts on each page, you can use the found_posts method of WP_Query : <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $portfolio = new WP_Query(array(‘post_type’ => ‘project’, ‘posts_per_page’ => 12, ‘paged’ => $paged)); if ($portfolio && $portfolio->found_posts >= 2) : while ($portfolio->have_posts()) : $portfolio->the_post(); echo “<div>”; the_title(); … Read more

using the loop on a page

To use template tags within a foreach loop outputting the results of get_posts, use the function setup_postdata() to populate the global $post with the data it needs. To style the first post differently, use a counter to keep track of which post you’re outputting. After finishing output, use wp_reset_postdata() to restore the $post global. wp_reset_query … Read more

2 loops in blog homepage

You can use this code to get 3 posts from category Featured $args = array( ‘category_name’ => ‘featured’, ‘posts_per_page’ => 3 ); $featured_posts = new WP_Query( $args ); if ( $featured_posts->have_posts() ): while ( $featured_posts->have_posts() ): $featured_posts->the_post(); // Here you can use the normal loop functions like ‘the_title()’ to display your // 3 posts from … Read more

show posts from one category with comments only

To retrieve all posts from a category, while preserving the original Loop query, you create a new query like so: <?php $testimonials = new WP_Query( array( ‘post_status’ => ‘publish’, ‘post_type’ => ‘post’, ‘posts_per_page’ => 30, // limit number of posts for which to get ALL the comments of ‘category__in’ => array( 2, 6, 18 ) … Read more