• Resolved markp

    (@markp)


    Hi all,

    In WP1.5 we have the new option to create Pages not just Posts.

    What I want to do is create a Page which will be the site’s home page. When users go to the site I want them to see that page.

    I’ve tried a few things. I’m already managing to get the site home page to appear in the Page template (as in default Kubrick) and not the Posts template (or any other template) by fiddling with the end of wp-blog-header.php:
    } else if ( is_home() && file_exists(get_page_template()) ) {
    include(get_page_template());
    exit;

    but it still shows the latest posts and not the page. I’ve tried writing the ‘ID’ of the page into a variable but I’m getting nowhere there either.

    Any ideas?

    I’m imagining that this type of setting might just become a standard option in the admin console.

    I’m using build ‘wordpress-2005-01-17’

    Cheers,

    Mark

Viewing 15 replies - 1 through 15 (of 71 total)
  • There have been requests for a home.php or front.php template that would be loaded instead of index.php for the site home. Would that work for you?

    Thread Starter markp

    (@markp)

    Hi,

    I don’t really want to redirect a user when they arrive at the domain. I guess I could do a header redirect upon detection that there are no post or get variables.

    So, not really what I’m looking for. It must be possible to do what I want to achieve.

    Where is it set that a call for the index.php with no post or get variables gives the user a page full of posts? If I can change this code then I’m sorted.

    Cheers,

    Mark

    It won’t be a redirect. home.php will be included from the blog header and no one will be the wiser.

    If the template loaded for the home page has a post loop in it, you will get a page of posts. The default index.php and page.php have a post loop.

    Thread Starter markp

    (@markp)

    Yeah. I just tried taking out the post loop (from page.php) and saw that I ended up with just the last post.

    So if home.php is included in the blog header where would it go? Surely I have to also take something out to prevent it getting a load of posts as well?

    I also want the home page editable as a wp Page (by the way!) and to appear in the automatically generated list of Pages.

    It appears that blog-header.php somehow sets up the $wp-query globally used object. It seems to me that if I can fill that object with the data I want (that will determine the page I want to show) then I will have acheived what I want to do. I’m just not experienced with php objects. 🙁

    home.php would go in the theme directory. It wouldn’t have a post loop. It would directly contain the content you want to show up on the front page rather than pulling from the DB. But, since you want to be able to use the WP page feature, you’ll need a “Make this page the front page” plugin. I’ll write one tonight.

    Thread Starter markp

    (@markp)

    I’ll be interested to see what you come up with.

    I’m still trying to suss out this $wp_query object. It must default to certain values that must be able to be changed.

    rboren, the home.php idea is phenomenal. I hope to see it implemented soon. Currently, I used a “template” page to achiev the same effect but a home.php or frontpage.php would be the most efficient. Thanks.

    Here’s the plugin. Hopefully the forum won’t munch on it too much. The plugin intercepts the query string before it is passed to wp_query. If we’re on the home page we insert a page id into the query string and return it. This altered string is what is passed to wp_query, making it look like a specific page was requested.

    <?php
    /*
    Plugin Name: Page to Front
    Version: 1.0
    Plugin URI: http://wordpress.org/
    Description: Choose a page from the DB to display as the front page of your weblog.
    Author: Ryan Boren
    Author URI:
    */

    // Put the id of the page you want to display here. To find the page id,
    // go to Manage->Pages in the admin UI and look at the ID column.
    $ptf_front_page = 1;

    function ptf_front_page($query_string) {
    global $ptf_front_page;

    $query = new WP_Query();
    $query->parse_query($query_string);

    if ($query->is_home) {
    $query_string = add_query_arg('page_id', $ptf_front_page, $query_string);
    }

    return $query_string;
    }

    add_filter('query_string', 'ptf_front_page');
    ?>

    Thread Starter markp

    (@markp)

    DONE IT!!

    I’ve inserted the following code after line 187 in classes.php
    if ( $this->is_home == true) {
    $this->is_home = false;
    $this->is_page = true;
    $this->query_vars['page_id'] = 2;
    }

    where ‘2’ is the ID of the page (in wp.posts) that you want to show on the home page.
    I don’t really know why this works. This is my first attempt at using objects in PHP.

    Thread Starter markp

    (@markp)

    Well done rboren! I’ve just tried your plugin and it works great. Basically it is doing just what my mod to classes does, but in a more elegant manner.
    However, I am getting:
    Warning: Cannot add header information – headers already sent by…page2front.php:29)
    in /home/…./wp-admin/admin.php on line 7
    then lines 8, 9 and 10.
    But *only* in the admin console.
    Note, this is WP 1.5 build ‘wordpress-2005-01-17’

    Probably some extra whitespace at the end of the plugin.

    Thread Starter markp

    (@markp)

    Sorted – it was whitespace that I’d accidentally pasted in.
    Gorgeous!
    Thanks Ryan.
    I’ve ditched my code and I’m now relying on your new plugin.

    ryan > Since your plugin redirects any request to the WordPress home page to a “static” page, how do you access the real blog index displaying the last posts ?

    Home.php would be perfect. It would be awsome if it ccan be displayed without a database query, so it will work even if my database server is down.

    Used your plugin Ryan … nice one. But do anyone know if it’s possible to remove the “no comment” link and “directory + date” link from just that page?

    Looks cleaner as a static home page when those are gone 🙂

Viewing 15 replies - 1 through 15 (of 71 total)
  • The topic ‘WP Page as static home page’ is closed to new replies.