I investigated Wordpress hierarchy and have created a php file called category-image-gallery.php the link to this is http://www.phoneographer.org/category/image-gallery/ having uploaded it and added it to my custom menu. I would like to set this as my home page but it's not listed as a Page in my reading settings screen (because it's not a static page I guess) so I can't select it. Is there any way to set this php 'page' (I guess page isn't strictly the correct term) as my home page?

Many thanks.


  • 1
    Would it be accurate to say that what you want to do is: Use a specific category archive index as the site front page? Nov 28 '12 at 17:59
  • 2
    I hope you'll forgive me if I don't use the correct terminology but basically I would like the URL phoneographer.org/category/image-gallery (which is category-image-gallery.php) to become phoneographer.org - I would include it in my bespoke menu as 'home' with the address phoneographer.org - hope that answers the question?
    – Skip
    Nov 28 '12 at 18:13

Create a file front-page.php with the following content:

locate_template( 'category-image-gallery.php', TRUE, TRUE );

That’s all.

For the theme’s functions.php

If you want to restrict the front page content to posts from that category, filter the front page query:

add_action( 'pre_get_posts', 'wpse_74225_frontpage_categories' );

function wpse_74225_frontpage_categories( $query ) 
    if ( $query->is_main_query() && is_front_page() ) 
        $query->set( 'category_name', 'image-gallery' );

    return $query;

But that would create a copy of your category archive: duplicate content, not a good idea if you want both pages be found in search engines.

To avoid links to that category archive you have to filter 'term_link' too:

add_filter( 'term_link', 'wpse_74225_category_link', 10, 2 );

function wpse_74225_category_link( $link, $term )
    if ( 'image-gallery' === $term->slug )
        return home_url();

    return $link;
  • @toscho I've given it a try - front-page.php works fine. I can see that it pulls the correct template to the front page. However, the add_action in functions.php doesn't pull in any posts. The only 'post' that appears is the 'page' currently set as my home page within reading settings in the admin panel. Any ideas? Also within functions.php I have an existing pre_get_posts action which strips various categories from the main 'blog' as they have their own 'page' (image-gallery being one) ... thought I'd mention in case part of the issue.
    – Skip
    Nov 28 '12 at 19:26
  • You cannot use that for a “static” front page. And yes, other filters will affect this query too, if you don’t test for is_front_page().
    – fuxia
    Nov 28 '12 at 19:28
  • @toscho thank you. I don't want a static front page. I want the template 'category-image-gallery and posts from the 'image-gallery' category to appear in the template. At the moment I have the template and a snippet from my existing front page appearing in it and none of the posts. Can you help further (I do not want to take all your time up). Skip.
    – Skip
    Nov 28 '12 at 19:41
  • Oh I think I see what you're saying I have to set 'Reading Settings' as front page displays 'your latest posts' rather than a 'static page' as it is at the moment. If I do that though what happens to all the other blog categories after I've filtered in functions.php? Currently I have 'posts page' set to a page called 'blog' but with some categories stripped out - I'm not sure where other posts would appear?
    – Skip
    Nov 28 '12 at 20:14
  • The other posts will appear on the category archive pages.
    – fuxia
    Nov 28 '12 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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