• I was wondering how I would create a second loop for my category page? I’m trying to create a loop for my blog and recipes. Here’s the code from it…

    <?php if ( is_category('blog')): ?>
    
    	<div id="content" class="about">
    		<div id="left_col">
    				<img src="<?php bloginfo('template_url');?>/images/logo_sm.png" class="left"><h2 id="ab">WHC Health Tips</h2>
    				<ul id="blog">
    					<?php if (have_posts()) : while (have_posts()) : the_post();?>
    						<li class="post">
    							<h3><a class="" href="<?php the_permalink();?>"><?php the_date();?> - <?php the_title();?></a></h3>
    							<?php echo better_excerpt('350', '...');?>
    							&raquo; <a href="<?php the_permalink();?>">read more</a>
    						</li>
    					<?php endwhile; ?>
    					<?php endif; ?>
    				</ul>
    				<div class="navigation"><?php posts_nav_link(' - ','&laquo; Newer Articles','Older Articles &raquo;'); ?></div>

    I want it to be able to check if it’s the blog category, or the recipes category. Thanks for the help in advance!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter thesandman2236

    (@thesandman2236)

    Would I just be able to add another loop within that loop?

    I want it to be able to check if it’s the blog category, or the recipes category.

    http://codex.wordpress.org/Conditional_Tags#A_Category_Page

    Would I just be able to add another loop within that loop?

    No. You’d need to use something like query_posts.

    http://codex.wordpress.org/The_Loop#Multiple_Loops

    Thread Starter thesandman2236

    (@thesandman2236)

    Thanks Esmi — since I already checked for the blog post, would it be in the same loop, or a 2nd loop?

    Thread Starter thesandman2236

    (@thesandman2236)

    Nevermind — just reread what you wrote, I’ll see if I can get this to work.

    Thread Starter thesandman2236

    (@thesandman2236)

    Alright I’m stumped. Most of these loops are to display 2 sets of data. Not one or the other.

    Exactly what is it that you’re trying to do? If it’s just that you want a slightly different display for the blog category compared to the recipes category, then you don’t need 2 Loops. Just a conditional right after the start of the Loop:

    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <?php is_category('Recipes') || in_category('Recipes') ) :?>
    [ do recipe stuff ]
    
    <?php else: ?>
    [ do standard stuff ]
    <?php endif;?>
    
    <?php endwhile; ?>
    <?php endif; ?>
    Thread Starter thesandman2236

    (@thesandman2236)

    <?php if ( is_category('blog')): ?>
    
    	<div id="content" class="about">
    		<div id="left_col">
    				<img src="<?php bloginfo('template_url');?>/images/logo_sm.png" class="left"><h2 id="ab">WHC Health Tips</h2>
    				<ul id="blog">
    					<?php if (have_posts()) : while (have_posts()) : the_post();?>
    						<li class="post">
    							<h3><a class="" href="<?php the_permalink();?>"><?php the_date();?> - <?php the_title();?></a></h3>
    							<?php echo better_excerpt('350', '...');?>
    							&raquo; <a href="<?php the_permalink();?>">read more</a>
    						</li>

    Something like this, category this OR category that.

    Can you try dropping that code into the WordPress pastebin and post the link back here. I can see some problems with it but I may not be seeing the complete code block.

    Thread Starter thesandman2236

    (@thesandman2236)

    Try http://wordpress.pastebin.ca/1583317

    One Loop with all of the conditionals set up before the Loop starts. You still had two Loops in there which would have caused problems. As the 2 original Loops were virtually identical, it makes sense to just have a single Loop but change the CSS ids and category titles to suit.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Category Page, 2 loops for different categories.’ is closed to new replies.