WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] 4 different categories on index? (5 posts)

  1. Doodlebee
    Member
    Posted 7 years ago #

    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!

  2. Chris_K
    Member
    Posted 7 years ago #

  3. Samuel B
    moderator
    Posted 7 years ago #

    You didn't say what happens when you call the code. Nothing? Screws up sight?
    I'm curious - sue me. :>)

    I'll give it a whirl and see what happens.

    Edit - ok, that's a great sight Handy. I forgot I had it in my bookmarks.

  4. Doodlebee
    Member
    Posted 7 years ago #

    samboll -

    Sorry. Blank page is what I get. I *wish* I could see the errors (because I know they're there) but it's not my server, and it's not exactly my client, either - so I don't have access to the logs or anything to see what the errors *are*. Totally sucks.

    I'm going to check out that link now Han :) Thanks!

  5. Doodlebee
    Member
    Posted 7 years ago #

    Yes! Terrific link, Han. Worked like a charm - thank you!

Topic Closed

This topic has been closed to new replies.

About this Topic