Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to use a category page as the home page of my blog. Is that possible and how can I do it? It tried it with a .htacces rewrite rule but that didn't worked.

share|improve this question

5 Answers 5

up vote 7 down vote accepted
+50

Update

Eliminating all of the other solutions, there is at least one remaining: template_redirect:

function wpse121308_redirect_homepage() {
    // Check for blog posts index
    // NOT site front page, 
    // which would be is_front_page()
    if ( is_home() ) {
        wp_redirect( get_category_link( $id ) );
        exit();
    }
}
add_action( 'template_redirect', 'wpse121308_redirect_homepage' );

You will need to pass the appropriate category $id, of course.

The benefit of redirecting at template_redirect is that you only get one template-load taking place, rather than a second redirect after the template loads.

Note that you can hook into the process even earlier, such as at pre_get_posts, thereby potentially saving an entire query request:

add_action( 'pre_get_posts', 'wpse121308_redirect_homepage' );

Original Answer

If all you want to do is display a specific category on the blog posts index, you can accomplish that with a simple filter of the main $wp_query at pre_get_posts:

function wpse1862_pre_get_posts( $query ) {
    // Only modify the main query
    // on the blog posts index page
    if ( is_home() && $query->is_main_query() ) {
        $query->set( 'category_name', 'category-slug-here' );
    }
}
add_action( 'pre_get_posts', 'wpse1862_pre_get_posts' );

If you want to modify the template, then you can do one of two things:

  1. Create a home.php with the desired markup
  2. Use template_redirect or home_template to force WordPress to include your category.php template.

Edit

And if you want the blog posts index URL to look like:

www.example.com/main

Then you can use a Static Front Page, and assign a static page called "main" as your blog posts index.

And if this is your objective:

I really want the redirect. I want the home page (http://example.com/) to redirect to the category page (which looks like http://example.com/main/)

...then the accepted answer is correct for your use case.

share|improve this answer
    
Sorry, no. I really want the redirect. I want the home page (http://example.com/) to redirect to the category page (which looks like http://example.com/main/), because I the categories are 'Editions' (by country) on the site and the default is US (main). I wish I could edit the bounty description to make this clear. –  its_me Nov 5 '13 at 14:22
    
You can edit the question to make that clear. And if your question is that much different from the OP, you should have asked your own question, rather than placing a bounty on this one. And: why do you want a redirect, specifically? A redirect is an implementation, not an end goal. Describe what you're actually trying to accomplish. A redirect may or may not be the only or best implementation. –  Chip Bennett Nov 5 '13 at 14:23
    
Chip, the reason/use case may be different, but the question is exactly the same, which is why I avoided another question. And as you can see, a similar answer has already been posted (although using query_posts, a less recommended method). –  its_me Nov 5 '13 at 14:24

Category page can't be home page (just doesn't work like that).

There are two other options:

  1. Limit home page to posts from specific category (close but not the same thing).
  2. Redirect home page to actual category page.

Since you seem fine with redirect try following. Create home.php template in your theme directory with following content:

<?php
wp_redirect( 'http://www.yoursite.com/category/category-slug' );
?>

There is probably some more tidy way to do this with hooks, but nothing I can think of right now.

share|improve this answer
    
Thanks, that's what I was searching for. WP should really document all those special PHP files better (like the maintenance.php). –  2ndkauboy Sep 15 '10 at 18:59
1  
Just be aware that this almost doubles server load for home page. WP core runs twice. Might be important factor if you have decent amount of visitors. –  Rarst Sep 15 '10 at 19:06

The most semantic way to do this instead of using a redirect (extra connection time) is to create a custom page template.

new page:

/* Template Name: New Homepage by Cat */

<?php query_posts('cat_id'=>'3');?>
<--insert loop-->
share|improve this answer
    
Yup, this is the one. Upload this template to your theme. Add a new page, set template to "New Homepage by Cat". The go to settings > reading > choose 'a static page' > front page = New Homepage by Cat... and your done... –  inTOWN Nov 7 '13 at 18:30

just add a category filter into your index.php query in your template. simples

share|improve this answer

If you want to redirect to a particular category i.e category id 3 then copy the content from category.php and make another template like category-3.php After that

    * Template Name: New Homepage by Cat 3*/

    <?php query_posts('cat_id'=>'3');?>
    <--insert loop-->

In wordpress reading we need to set home as posts page and for home page select the New Homepage by Cat 3 as a template.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.