4 different categories on index?
-
Okay, I *know* this is a “Loop” question. I’ve been trying for a few hours now to implement it using the Loop, because I *know* it can be done (at least, I think it can be), but my formatting must be nuts or something. COuld someone check/edit my stuff here for me? I don’t know if it’s hte lack of coffee or what, but I just don’t know why this isn’t working.
Basically, I need 3 columns on my index page. Each column will get content from the database by catgory. So, for example, category 1 is “Music, category 2 is “Books”, and catageory 3 is “Art”. So, if I write posts in each of these catagories, “Music” will be in the left colum, “Art” in the right and “Books” in the middle. If I update *only* the “Books” catageory, the new post will take the place of th eold, but “Music” and “Art” will remain in their spots (unless I put a new post in that category).
Now, what I came up with is something like this (I’ve tried a few variations) but it’s just not working at all. So if someone could take a peek and correct me, I’d sooooo appreciate it:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php if ( in_category('1') ) {
<div class="section1">
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
</div>
<?php } ?>
<?php if ( in_category('2') ) {
<div class="section2">
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
</div>
<?php } ?>
<?php if ( in_category('3') ) {
<div class="section3">
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
</div>
<?php } ?>
<?php endwhile; ?>
<?php endif; ?>It seems to me that, as long as there are posts in each of these categories, this *should* work. But I am apparently very much mistaken, because it doesn’t.
Oh yes, and the title says “4 categories”….I also need a 4th, separate Loop run in the header. Is it going to hurt/conflict with anything if I call totally separate Loop in the header?
Thanks a bunch for any help you can give!
The topic ‘4 different categories on index?’ is closed to new replies.