WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Modifying the front page (4 posts)

  1. Gentist
    Member
    Posted 8 years ago #

    I want to modify the front page of my WP installation so that it only displays posts from certain categories. Is there an easy way to do this, or do I have to mess with PHP? If I have to mess with PHP, which file controls the front page?

  2. mjwood
    Member
    Posted 8 years ago #

    I would suggest reading up on "The Loop" in the Codex. Basically, your front page is controlled by the index.php. This file will have a loop in it which esentially loops through your database and displays the posts.

    While I'm not a php expert (really more a novice), I'm sure there is some form of conditional logic that could be used in this loop to only display posts in certian categories. I'll let someone with more php knowledge jump in here.

    Good luck!

  3. mjwood
    Member
    Posted 8 years ago #

    Or... after I did a bit of searching found that Moshu recommended this plugin for another person that does what you want, I think.

    http://ryowebsite.com/?p=46

  4. Gentist
    Member
    Posted 8 years ago #

    I read up on the loop thing (I actually did that before posting this question), and fixed the problem using one line of PHP code. I just wanted to know if there was an easier way, since the way I did it isn't very clean (I have to manually keep track of the category IDs, should they ever change).

    Here's my code, placed after the start of "The Loop":

    <?php if (!in_category('4') && is_home()) continue; ?>

    If there's a better way of doing that, like, say, making sure it's still valid, even if the category ID would change (I'd rather it keeps track of it using the name of the category), I'd like to know.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.