• I am using my category.php file to set the style for each category page once selecetd as they will all look the same but my pages are not filtering:

    <div class="row">
    
    			<?php query_posts('showposts=-1'); ?>
    			<?php if (have_posts()): while (have_posts()) : the_post(); ?>
    				  <div class="col-xs-3">
    				   <div id ="top-news-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
    				 </div>
    			<?php endwhile; endif; wp_reset_query(); ?>
    	  </div>

    The above code display all posts but I need it to display all posts of the current category as this page is what is displayed once a category link has been selected.

Viewing 1 replies (of 1 total)
  • Thread Starter Fi Fi P

    (@fi-fi-p)

    I fixed it with the below code!

    <div class="row">
    	 <?php
    		global $post;
    		if(is_category() || is_single()){
    		foreach(get_the_category() as $category)
    		{
    		$current = $category->cat_ID;
    		$current_name = $category->cat_name;
    
    		$myposts = get_posts(array('category__in' => array($current)));
    
    			}
    
    		}
    
    		foreach($myposts as $post) :
    		setup_postdata($post);
    		?>
    				<div class="col-xs-3">
    						<div id ="top-news-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div>
    				</div> 
    
    <?php endforeach;wp_reset_query(); ?>
    
     </div>

    My issue now is adding a message if there are no posts in that category. I tried:

    <?php endwhile; else: ?>
    <p>Sorry, no posts matched your criteria.</p>
    
     <?php endif; ?>

    But that gives me the dreaded white screen, any help would be greatly appreciated!

Viewing 1 replies (of 1 total)
  • The topic ‘Category page’ is closed to new replies.