WordPress.org

Ready to get started?Download WordPress

Forums

Setting up static home page with blog behind (6 posts)

  1. nick_nielsen
    Member
    Posted 5 years ago #

    I want to have a static home page which gives a general introduction to my site with static gallery pages and a conventional blogging section. I have what claims to be an up to date book about wordpress theme development which told me to make a home.php - this of course, as I found out, stops me using index.php to output the blog.

    So I changed home.php to intro.php and got it to register as a template I then created a blank home page and set this up in "read" to be my static home page. I got back the use of index.php for the blog but I completely lost a mini loop I had set up in the home page !

    The mini loop should show titles and excerpts from the last 3 posts when attached to the new home page all I get is the title of the home page, interestingly enough, "home" and a blank. None of the posts show.

    How do I

    1. get a miniloop as described to show ?
    2. Not have any trace of the home page title show ?

    I have to say that the codex is a useless bloody muddle on this subject - very confusing, even for someone who is not completely without experience.

  • nick_nielsen
    Member
    Posted 4 years ago #

    I think I got it sorted !
    What follows is a solution which seems to work.
    I made a file called "intro.php."
    by putting

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

    at the top of your new template file it is registered as a usuable template - you create a "home" static page and you link it to the "intro" template. You then go to "read" in admin and set up your staic "home" page as your home page - this means that you can point a "go to my blog link" to index.php and you're on a conventional blogger's page.

    The second part of my problem I solved by taking out the loop altogether in the template, and instead using "get_posts()", setting up a loop thus : (go to codex for variants)

    <?php
     $postslist = get_posts('numberposts=3');
     foreach ($postslist as $post) :
        setup_postdata($post);
     ?>
    ...
    <?php endforeach ?>

    this gives the last 3 posts which allows you to make calls such as
    "<?php the_title(); ?>" and "<?php the_excerpt(); ?>" which you embed in your HTML.

    I do not know if this is a definitive solution and would appreciate comments an improvements. For the moment it works !

  • jonisolis
    Member
    Posted 4 years ago #

    I thought there was an easy way to make a static home page now. Is this the only way to do it? Is this the way WordPress is designed to work if you want a static home page?

  • xtra
    Member
    Posted 4 years ago #

    Go into Settings > Reading

    From there you can select a static page to be the home page

  • MichaelH
    Member
    Posted 4 years ago #

  • nick_nielsen
    Member
    Posted 4 years ago #

    jonisolis hi !
    It is easy, which is to say you can select any static page to be your "Home Page"

    My solution is for a specific situation :

    • A home page that bears no relationship to my "default" static pages - including a change in the header and
    • Wanting to have a traditional "blog" section.

    If you do want a different Home page structure, you have to make a template that reflects the structure you want and attach your static page to the template.

    The point where there is a lot of confusion is about home.php and the template hierarchy. What I didn't realise, and what the author of my book did not make clear is that using home.php takes index.php (which gives you the traditional blog appearance) completely out of the loop.

    If you do not want the traditional blog format anywhere on your site, and you only want people to navigate your posts through categories, tags, or whatever filter you want to use, then home.php is fine.

    I just find there is a certain charm in a blog in the way posts blunder from topic to topic seemingly without order...

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags