WordPress.org

Forums

Setting the front page to specific category archive - 2013 (2 posts)

  1. garrettmojica
    Member
    Posted 2 years ago #

    I'm looking to get some help on setting the front page so that it will only display posts from a specific category archive.

    Does anyone know how to do this?

    Any help to previous threads, articles or tutorials would be greatly appreciated.

  2. Jesper van Engelen
    Member
    Posted 2 years ago #

    There seems to be a plugin available that was created solely for this purpose: http://wordpress.org/extend/plugins/frontpage-category-filter/.

    If you would like to go for a non-plugin approach, you could hook into the pre_get_posts action to manipulate the main query. Make sure you first check whether it is the home page and whether the query you are checking is actually the main query.

    function yourprefix_homepage_query_category($query)
    {
    	if ($query->is_home() && $query->is_main_query()) {
    		$query->set('cat', YOUR_CATEGORY_ID);
    	}
    }
    
    add_action('pre_get_posts', 'yourprefix_homepage_query_category');

    You can check out the Codex entry for pre_get_posts, where you will find an example for excluding certain categories, which is very similar to what you're trying to achieve.

    http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts#Exclude_categories_on_your_main_page

Topic Closed

This topic has been closed to new replies.

About this Topic