• Hi guys,

    I have a problem with blog posts. I’ve setup a normal Blog page where I only show posts from a “news” category and now I would like to have a second blog page where I would show only posts from category “references”. So far so good. Problem is with how many posts should be posted on one page. In my case 7, but when I enter 5 new posts in a second category, then I have on my Blog page only two posts. It looks like it has something to do with an input order although I hook up only on a category. Any idea why this happens?

    This is my Blog page code

    if (have_posts()) :
       			while (have_posts()) : the_post();
    			   if ( in_category( 'news' )) {
          				echo '<span class="date">';
    					echo get_the_date();
    					echo '</span><br/>';
    					echo permalink_anchor();
    					echo '<br/><h4>';
    					echo '<a class="permaLink" href="';
    					echo the_permalink();
    					echo'" title="';
    					echo the_title_attribute();
    					echo'">';
    					echo the_title();
    					echo '</a>';
    					echo '</h4><br/>';
    					echo get_the_content('<br/><br/>Read more...');;
    					echo '<hr/>';
    			  }
       			endwhile;
    		endif;

    Thanks for your help

Viewing 1 replies (of 1 total)
  • The problem is that you are skipping posts inside the Loop. WP counts all the posts in all categories (unless you change the query), but you are not showing all of them.

    To remedy this, you need to change the query. Try changing the code above to this:

    global $query_string;
    query_posts( $query_string . '&category_name=news' );
    if (have_posts()) :
       while (have_posts()) : the_post();
          echo '<span class="date">';
          echo get_the_date();
          echo '</span><br/>';
          echo permalink_anchor();
          echo '<br/><h4>';
          echo '<a class="permaLink" href="';
          echo the_permalink();
          echo'" title="';
          echo the_title_attribute();
          echo'">';
          echo the_title();
          echo '</a>';
          echo '</h4><br/>';
          echo get_the_content('<br/><br/>Read more...');;
          echo '<hr/>';
       endwhile;
    endif;

    That way, WP includes only the category ‘news’ in the posts selected.

Viewing 1 replies (of 1 total)

The topic ‘blog posts’ is closed to new replies.