WordPress.org

Ready to get started?Download WordPress

Forums

Lesson: How to make a static page your "home" page (44 posts)

  1. lawtai
    Member
    Posted 9 years ago #

    Alright, I figured I'd make this a lesson post since I've seen a few people wanting to do this. This are the steps that need to be taken if you want to have a wordpress "page" your home page before people can see your blog.

    1. First step is to create a plugin with Ryan's plugin:


    <?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');
    ?>
    '`

    You can name it something like pagetofront.php or whatever you want really.

    2 . Next, create the page that you want people to see when they first come visit your site. You could make it as simple as just having text with your theme look, or you could create a whole new template for your home page and then just create it as a page.

    If you're making a new template, don't forget to add the following to the top of your php file:

    <?php
    /*
    Template Name: Home
    */
    ?>

    3. Note the number that the page is given when you create the page, and edit the plugin with the page that you want as your new "home page."

    4. Next up, you'll need to edit your permalink structure so that you'll be able to get from your home page to the rest of your blog. Without setting up the permalink structure, I believe that you'll have no way of getting back to your blog since the plugin will keep redirecting you back to the home page.

    You'll want your permalink structure to look something like this:

    WordPress Address: http://mydomain.com/blog
    Blog Address: http://mydomain.com/
    Permalink Structure: /blog/%year%/%monthnum%/%day%/%postname%/

    That should be all that you need to do. You'll now be able to have a static home page which is part of wordpress.

    All of this is assuming that you have wordpress installed in your root directory instead of a folder. You could do this if you had wp installed in a folder, but then your home page would be located at mydomain.com/wp with your blog then at mydomain.com/wp/blog.

    Hope this helps!

  2. Lorelle
    Member
    Posted 9 years ago #

    Thanks!

  3. trevorturk
    Member
    Posted 9 years ago #

    there's something about this in the codex. feel free to update it:
    http://codex.wordpress.org/Pages#Using_a_Page_as_the_Front_Page

  4. lawtai
    Member
    Posted 9 years ago #

    heh it must've been recently added.

  5. Lorelle
    Member
    Posted 9 years ago #

    Yep. About a week ago. That's the way of it. I'd compare notes to see if they match, and if they don't, let us know.

    And there is nothing wrong with your lesson here that I can tell. Even if it is in the codex, we need to talk about these issues here. The whole reason I started these Lessons were because the Codex was down but I happened to have some of the pages saved to my computer. Not everyone looks to the Codex first because it is still "new", so it doesn't matter.

    And by posting it here, you get a chance to learn even more about the techniques and how others do it.

    Keep up the great work and we need more of these!

    If you have a question about posting a Lesson, or you want to see some of the suggestions for Lessons, check out this thread:
    Lessons: Getting Started with Lessons

  6. docker
    Member
    Posted 9 years ago #

    Here is my solution :

    1. Copy page.php -> home.php
    2. Add query_posts("page_id=2"); (where page_id is your page) before the Loop
    3. Copy index.php -> news.php and add at the top
    <?php
    /*
    Template Name: News
    */
    ?>
    And add query_posts("showposts=10"); before the Loop
    4. Make a page named News and assign template News to it

    All works fine, i think. At least for me. And all pages in sidebar lists automatically.
    Basicaly it's the same solution as above, but there is no need to change permalinks and adresses.

    Is there any bugs or minuses ?

  7. lawtai
    Member
    Posted 9 years ago #

    yea, I think your way'll work too, it's just that using the plugin allows for less editting of your index.php file, although your way doesn't require a change in permalinks.

  8. yogaboat
    Member
    Posted 9 years ago #

    Docker is your solution something taht is done without Ryan's plugin?

  9. lawtai
    Member
    Posted 9 years ago #

    docker did it without the plugin, but he also had to manually add code to his files. If you're comfortable with that, then you don't need to use Ryan's plugin.

  10. Root
    Member
    Posted 9 years ago #

    My solution is simpler still and prevents this rampant hackery. Run your front page off home.php. No if / else malarkey. Switching to index for the blog by default . No need to hack your index. Get this - no pages necessary or accordingly no template association and NO PLUGIN NEEDED.

  11. yogaboat
    Member
    Posted 9 years ago #

    Pardon my ignorance, I'm new to all of this and THOROUGHLY confused at this point.

    I installed Ryan's plug-in. However I can not get to the blog. Not only that, but the archives pages show a shortened sidebar. Site is here:

    http://cottonmill.info

    Root what do you mean by "run your front page"? Are you saying rename index.php to home.php?? Where does the new page I created to be the front page fall into that setup?

  12. Root
    Member
    Posted 9 years ago #

    It is a little used fact that when WP loads the very first file it tries is home.php . Consult the sages at the Oracle of Codex if you need more details. What does that mean ? You can create a home page by simply copying index.php as home.php. It will then be your front page. Then you can hack it to death . In your case that will involve simply deleting everything you dont want . If you want an early preview of a home / index switch from 3>2 cols you can just peek at my new template (very under construction) Aphrodite . You saw it here first. :)

  13. docker
    Member
    Posted 9 years ago #

    Ok, the point really was to :

    1. Make a static page your home page, and possibility to change it content from admin panel.
    2. Get a fancy link to back to your blog with all your posts, like you get it usually without hacks or plugins. This link have to be in pages list automatically.

    Of course i used home.php functionality in my hack. But sorry for all - my hack not works properly :( Try to reach next page if you have more than 10 posts and you will get 404 error.

    lawtai have a good solution, but i don't know why it not works for me (i always have 404 error when try to get my posts, and even if it's working - i have to manually add link to blog to menu. It's simple but i'm lazy :).

    Now i'm trying the way with plugins - Ryan's Page to Front, and Owen's Redirectify.

    Will see....

  14. Root
    Member
    Posted 9 years ago #

    Well mine seems to be running fine.

  15. yogaboat
    Member
    Posted 9 years ago #

    Root if you have the time, I could use some help with this. Be forewarned I'm new to coding - I hack my way thru most of the time. yogaboat at hotmail dot com.

  16. 2bak860
    Member
    Posted 9 years ago #

    But using Ryans plugin, is there an EASY way of getting to the blog (in the root folder).

    At the moment I can only do it through rosschapman.com/2005/ - but it's not a sure fire answer - I'd ideally like rosschapman.com/blog/

  17. Root
    Member
    Posted 9 years ago #

    yogaboat - I would be happy to help. But the forum is the forum. Post your question here and we will try to get you all fixed up.

  18. Madiebeartri
    Member
    Posted 9 years ago #

    This is my front page

    http://www.beartribenet.com

    this is my log page

    http://www.beartribenet.com/log

    I didn't do this my child did. Don't you just hate it when your child cando something you can't. : )

  19. robfay
    Member
    Posted 9 years ago #

    Greetings!

    1. Are most people here now reliably using Ryan's plugin?

    2. When I create the plugin, I assume I drop it into my plugin directory?

    3. Can people post more examples of their sites having followed this method?

    Thanks

  20. vkaryl
    Member
    Posted 9 years ago #

    Root dear, what did you do with Aprodite? I'm getting a 404 (a real one, okay? *laughing*) I wanted to download it....

  21. breger
    Member
    Posted 9 years ago #

    Ryans plugin works great but the only problem I have is that the date of the post/page is displayed and I would rather just have the content without a date. Can I do this?

  22. Root
    Member
    Posted 9 years ago #

    @Madiebearti. Once you get into home.php being your front page it will reside in the same directory as the rest of your blog stuff. All this stuff in this thread is redundant and unnecessary.

  23. lawtai
    Member
    Posted 9 years ago #

    breger, take out the date call in your content section.

  24. Denis de Bernardy
    Member
    Posted 9 years ago #

  25. Root
    Member
    Posted 9 years ago #

    What is it with you guys and plugins?. This functionality is built into WP.

  26. Denis de Bernardy
    Member
    Posted 9 years ago #

    er, nope. wp only allows you to create a home.php file. and the wp query will seek to stick the latest posts on it.

    Ryan's plugin will occur before the wp query. basically, it adds the home page id argument to the query. the downside is that your page will answer to is_page() rather than is_home(), and you'll need to configure the page to use a separate template manually.

    my plugin bypasses the wp query clause _after_ the query detects that you're on the front page. thus, you can safely use is_home(), and home.php will automatically be for your template if the file is present.

  27. peterpoe
    Member
    Posted 9 years ago #

    I used this method on infinipedia.net

    • I created the "Page to Front" plugin and made it refer to a page with a custom template
    • I created another page for the blog main page named "eat" (with a custom template too)
    • Changed my blog's homepage in Options to http://www.infinipedia.net/eat

    Now http://www.infinipedia.net opens the custom homepage, but all internal links to the homepage take me to the blog's main page. Twisted but works.

  28. Root
    Member
    Posted 9 years ago #

    Er no not quite. Once you have home.php you can edit / delete the loop. The benefit of using a separate template is that the file can be edited locally and you can use ftp. It is not a meta file like a page. Plus if you want to use php in the template it is already set up.

  29. kickass
    Member
    Posted 8 years ago #

    trevorturk said:
    there's something about this in the codex. feel free to update it:
    http://codex.wordpress.org/Pages#Using_a_Page_as_the_Front_Page

    Obviously someone did "feel free to update it" since most of this information is missing . . .

  30. truenorth
    Member
    Posted 8 years ago #

    Root -

    I understand the logic behind using home.php, however this seems to effect index.php. Now neither show any posts.

Topic Closed

This topic has been closed to new replies.

About this Topic