• I’ve been having a problem for weeks now with showing category posts on the category page? and i cant seem to figure the problem.
    When i click on my category although it has posts it doesnt show them, it just has a blank page.

    My website is https://www.nomorenoodles.co.uk
    When i try to look at my posts from the blog category all i get is a blank page: https://www.nomorenoodles.co.uk/?cat=3

    This is my code in my category-3.php file and i dont know whats wrong…

    <?php get_header() ?>
    
      <div id="featured" class="small">
      	<?php include(TEMPLATEPATH . '/includes/featured-small.php'); ?>
      </div>
    
    	<div id="main-top"> </div>
      <div id="main">
        <div id="maincontent">
    
    <?php
    query_posts('cat=3');
    ?>			
    
    			<div class="clearboth"></div>
    			<div class="navigation">
    				<div class="alignleft"><?php next_posts_link('&laquo; Previous Posts') ?></div>
    				<div class="alignright"><?php previous_posts_link('Next Posts &raquo;') ?></div>
    			</div>
        </div>
    
    	<?php get_sidebar() ?>
        <div class="clearboth"></div>
      </div>
    
    <?php get_footer() ?>

    Can anyone help?

Viewing 9 replies - 1 through 9 (of 9 total)
  • You don’t have a loop in your code…

    <?php
    query_posts('cat=3');
    ?>
    
    missing--><?php if (have_posts()) : while (have_posts()) : the_post(); ?>		
    
    missing--> ---YOUR STUFF (title, permalink, author, date, etc.---
    
    missing--><?php endwhile; ?>

    Look in your other files, like index.php, to see how to buid a loop…

    S.

    Also, if you’re file is called “category-3.php” you don’t need the query – it’ll already pull that template for that category.

    Thread Starter spicer

    (@spicer)

    I didnt think i needed the query but because when i clicked on the category none of the posts show up i thought there must be a problem.
    I read that when category.php doesnt exist which it doesnt it pulls the template from index.php and when i clicked on my category no posts were shown so i thought it must need a query.

    This’ll help you a bit on that question:

    Template Heirarchy

    WordPress actually looks to use index.php *last*. It’ll first look for the specific category ID, then a general category file, *then* index.php.

    Just so you know ??

    If it didn’t pull the post – well my guess is the solution mentioned above. If you don’t have a Loop, nothing’s gonna show.

    Thread Starter spicer

    (@spicer)

    Thanks for your comments.

    My new category-3.php looks like this but it is still not pulling the posts as you can see from https://www.nomorenoodles.co.uk/?cat=3

    <?php get_header() ?>
    
      <div id="featured" class="small">
      	<?php include(TEMPLATEPATH . '/includes/featured-small.php'); ?>
      </div>
    
    	<div id="main-top"> </div>
      <div id="main">
        <div id="maincontent">
    
    <?php
    query_posts('cat=3');
    ?>
            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    				<?php if($counter==1){
    				  $counter++;
    				} else { ?>
    					<div class="postwrapper clearfix">
    						<div class="bubble"><?php comments_popup_link('0', '1', '%'); ?></div>
    						<h1 class="post"><a id="post-<?php the_ID(); ?>" href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a> <?php edit_post_link('Edit'); ?></h1>
    						<div class="posted">Posted on <span><?php the_time('l, F j, Y'); ?></span> in <span><?php the_category(', ') ?></span></div>
    						<?php the_content('Continue Reading'); ?>
    
    						<?php if (function_exists('the_tags')) { ?>
    					  	<?php the_tags('<div class="tags">Tags: ', ', ', '</div>'); ?>
    						<?php } ?>
    						</div>
    				<?php $counter++; } ?>
    
    		<?php endwhile; ?>
    
    		<?php else : ?>
    			<h1>Not Found</h1>
    			<p>Sorry, but you are looking for something that isn't here.</p>
    			<?php include (TEMPLATEPATH . "/searchform.php"); ?>
    			<div class="postmeta"></div>
    		<?php endif; ?>
    			<div class="clearboth"></div>
    			<div class="navigation">
    				<div class="alignleft"><?php next_posts_link('&laquo; Previous Posts') ?></div>
    				<div class="alignright"><?php previous_posts_link('Next Posts &raquo;') ?></div>
    			</div>
        </div>
    
    	<?php get_sidebar() ?>
        <div class="clearboth"></div>
      </div>
    
    <?php get_footer() ?>

    I just dont know what the problem is, so annoying and just about given up im just typing news posts straight into the page now.

    well, again, you don’t need the query. What’s the counter for? And you’re telling the site that if there’s posts, and while you have posts to do nothing, except as 1 to whatever number you’re counting. You don’t even have that echoed out. You don’t have the display for any actual content because you’re telling it to *not* display a post if it finds one, and if it does find one, then to display it (which it won’t, because if it finds one, it won’t display it.)

    What in the world are you trying to do?

    Thread Starter spicer

    (@spicer)

    As you can see I’m very new to programming. All i am trying to do is get the category page to show the posts from that category.

    Well, like I said, as long as the name of your file is “category.php” or “category-X.php” (where X is the ID of the category), then it’ll show. You don’t need the query – it already does it.

    Look at the default template as an example.

    i was facing similar problem for my blog https://www.crazybulb.com
    when i used to click on category, i used to get a blank page.

    I faced this problem after I transferred my blog to a new domain.

    I diagnosed the problem to archive.php and archives.php file. both the files were blank. so I downloaded my theme folder fresh from internet. copied the two files into my active theme’s folder and my categories started showing post in https://www.crazybulb.com

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Problem with query_posts showing category posts?’ is closed to new replies.