TheSandman2236
Member
Posted 5 months ago #
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', '...');?>
» <a href="<?php the_permalink();?>">read more</a>
</li>
<?php endwhile; ?>
<?php endif; ?>
</ul>
<div class="navigation"><?php posts_nav_link(' - ','« Newer Articles','Older Articles »'); ?></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!
TheSandman2236
Member
Posted 5 months ago #
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
TheSandman2236
Member
Posted 5 months ago #
Thanks Esmi -- since I already checked for the blog post, would it be in the same loop, or a 2nd loop?
TheSandman2236
Member
Posted 5 months ago #
Nevermind -- just reread what you wrote, I'll see if I can get this to work.
TheSandman2236
Member
Posted 5 months ago #
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; ?>
TheSandman2236
Member
Posted 5 months ago #
<?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', '...');?>
» <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.
TheSandman2236
Member
Posted 5 months ago #
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.