WordPress.org

Ready to get started?Download WordPress

Forums

Home.php loop for only one category? (7 posts)

  1. vavroom
    Member
    Posted 8 years ago #

    Ok, I've been looking all over the place and I can't seem to figure out exactly how to do this.

    What I want to do is to have a home page that has some static text, and a loop (mini?) displaying the posts only from one category.

    I came up with this:
    <?php if (!in_category(7)) continue; ?>

    <div class="post" id="post-<?php the_ID(); ?>">
    <h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    <div class="storycontent">
    <?php the_content("Continue reading the " . the_title('', '', false) . " article"); ?>
    </div>
    </div>

    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>

    This, I thought, worked fine, until I started adding more content! It does the trick if, and only if, the posts in the news category (ID=7) are the very latest in date.

    So, how would I do it? Create the home page loop so it only looks up one category, and displays the posts from that category, regardless of more recent posts in other categories?

    Any ideas would be very welcome

  2. freo4cup
    Member
    Posted 8 years ago #

    Wow that is sure a lot of code, if you just want one category to show use the front-page-filter plugin. I recently solved this problem myself.

    Hope that helps!

  3. vavroom
    Member
    Posted 8 years ago #

    Doesn't the front-page-plugin work on index.php, rather than home.php?

  4. freo4cup
    Member
    Posted 8 years ago #

    I'm not sure but it worked for me here is the address.

    If you want to apply it to another page it might be worth altering the code in it to make it applicable to that page.

    http://smallestbusiness.com/2006/03/02/front-page-filter-plugin/

  5. vavroom
    Member
    Posted 8 years ago #

    Thanks for that. I'll have to look at it. I'm not much of a code jokey, so not sure about altering the code, but... One thing that I see is that the plugin doesn't work on subdomains (well, that's my reading of his page). Sooo, we'll see :)

    Cheers

  6. winspire
    Member
    Posted 8 years ago #

    oops

  7. jenseo
    Member
    Posted 7 years ago #

    I also have this kind of problem, but the frontpage filter page seems to be down. I have tried google and this location, but cant find it anywhere else. Is there anyone who know if i can get this plugin elsewhere?

    Thank you!

    // Jens Filipsson.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags