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 know I can set a static page as the homepage but is it possible to set a single custom post as the site front page?

I created a custom post type called "portfolio" where users can add all the work they have done as posts and I need one of those posts to display as the homepage, exactly as if you would set a static front page in the reading settings.

Thanks in advance!

share|improve this question
    
Can you broaden the scope of the question a little? Why are you trying to make a post the homepage? –  m0r7if3r Feb 15 '12 at 20:19
    
Well it's a client's requirement, I created a custom post type called "portfolio" where he adds all the work he's done and he just wants one of those posts to display as the homepage, exactly as if you would set a static front page in the reading settings, updating question. –  javiervd Feb 15 '12 at 20:24
add comment

3 Answers 3

up vote 6 down vote accepted

You don't want a post to be the front page, you want a custom post type entry to be the front page. Now that we have the terminology right, yes it's possible.

A client once asked me to do the exact same thing. They had a custom post type they needed displayed on the front page. Doing so was as simple as adding a filter to allow them to select a "stack" (their custom post type) from the reading page:

function add_pages_to_dropdown( $pages, $r ){
    if ( ! isset( $r[ 'name' ] ) )
        return $pages;

    if ( 'page_on_front' == $r[ 'name' ] ) {
        $args = array(
            'post_type' => 'portfolio'
        );

        $portfolios = get_posts( $args );
        $pages = array_merge( $pages, $portfolios );
    }

    return $pages;
}
add_filter( 'get_pages', 'add_pages_to_dropdown', 10, 2 );

Then it's just a matter of styling your templates to use the data correctly.

share|improve this answer
1  
Up-voting your answer as the best approach. My answer corresponds to what the original question was, rather than to the question as-edited - which is something completely different than the original question. /sigh –  Chip Bennett Feb 15 '12 at 20:53
    
That's great, I like Chip Bennett answer as well but this one's definitely quicker. –  javiervd Feb 15 '12 at 21:10
add comment

There are many ways to accomplish this, though some are more advanced than others:

  1. Mark the blog post as sticky, and then set Posts per Page to 1 (Dashboard -> Settings -> Reading)
  2. Create a custom front-page.php template, and query the post in question, either via the sticky post designation, or via custom post meta
  3. Create a custom front-page.php template, and create a dynamic sidebar (i.e. Widget area), in which you add a Widget to display the post in question
  4. (Insert lots of other methods here...)

But I have to ask: why not just put that blog post content in a static Page, and then assign that static Page as the Front Page?

Edit

Based on your question clarification:

Well it's a client's requirement, I created a custom post type called "portfolio" where he adds all the work he's done and he just wants one of those posts to display as the homepage, exactly as if you would set a static front page in the reading settings, updating question.

You would need to use one of the following methods:

  1. Filter the page_on_front dropdown, as @EAMann suggests
  2. Create a front-page.php template file, that queries the correct Portfolio post, via custom post meta or other means
share|improve this answer
    
Well I was thinking about that last suggestion and I avoided it because I'd end up with 2 identical posts/page, plus I thought it'd be rather simple since setting a static front page is easy but I might go with that option. –  javiervd Feb 15 '12 at 20:28
1  
Don't duplicate the content. Add the content as a static page rather than as a blog post. In most use cases, anything suitable/desirable as site front-page content more resembles static page content than it does blog post content. –  Chip Bennett Feb 15 '12 at 20:31
    
+1 I'd vote +2 for re-writing your answer in a comment :) –  kaiser Feb 15 '12 at 20:38
add comment

How about setting a custom meta field for "Use as Homepage", then query for that meta and get the associated post(s) and output them...naturally all of this would be in front-page.php

share|improve this answer
add comment

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.