Category on front page? (2 posts)

  1. snakeyman2
    Posted 1 year ago #

    Is there a way to have a category page as the front page?

    I currently have the standard static frontpage:

    And want to have this instead:

    I haven't found any plugins to do that. I have tried "List category posts" plugin so that I could insert category posts in a page and then select it as front page, but that does only list links to them.

    Any help much appreciated

  2. Steven Jones
    Posted 1 year ago #

    So if you change the setting back to 'Your Latest Posts' then that means instead of requesting the page's content on the homepage you're back to requesting the latest x amount of posts (default is 10).

    You can then alter the query using the pre_get_posts filter.

    function wp_only_horses( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'cat', '4' );
    add_action( 'pre_get_posts', wp_only_horses' );

    So replace the 4 with the ID of your category.

    In the function we're saying that we only want posts from that category, and we're only altering the query if it matches the is_home() condition (which is does when we set the reading settings to your latest post) and then only the main query (i.e. so it doesn't effect things such as widgets).

    You can paste this code in your functions.php file.

Topic Closed

This topic has been closed to new replies.

About this Topic