• Hi, i have done a bit of searching and haven’t found anything that helps me yet. I want to display the latest posts on a page named ‘Blog’ but im not sure how to do this i have seen some people say you can just change it under the settings->reading bit in the back-end but this does not work for my page, i am guessing the blog.php file has to have some kind of coding in it for this to work? I cant find anything to help, so any help would be great.

Viewing 15 replies - 1 through 15 (of 18 total)
  • If you create a blank page named ‘Blog’ and select it as the ‘Posts page:’ in Admin->Settings->Reading, with ‘Front page displays’ set to ‘A static page’, the home.php file will be used if it exists. If home.php does not exist, then index.php will be used. Normally you do not need to do any special coding because index.php defaults (in most themes) to showing the latest posts.

    All of this can be changed by a theme, so your theme might be different.

    Thread Starter lukewilde

    (@lukewilde)

    Well i want it to work with what i have setup so far: https://www.lsw-design.com/tf/blistex would making the blank page and setting it to posts page work to show the posts on my blog page i have at the moment?

    I can’t say for sure, but it is easy to try and easy to undo (provided you back up first!).

    Thread Starter lukewilde

    (@lukewilde)

    Well i don’t know how to get this working, Can anyone please help me to get my blog page to show all the posts? Searched through so many tutorial sites and through google and found nothing that has helped me.

    Do you have a static front page set in Admin->Settings->Reading? If so, do this:

    • Create a blank Page named Blog unless you already have one a page named Blog.
    • In Admin->Settings->Reading, set Blog as the posts page.

    That should be all you need to do.

    Thread Starter lukewilde

    (@lukewilde)

    i have edited the index.php file for my home page and i can’t select that as the static front page, and just setting the page named blog as the posts page does nothing, as that is what i have set it to now and the page is still blank.

    OK. You have already hijacked your blog page by modifying index.php. You need to undo that to get the blog page back.

    Rename the index.php to frontpage.php and make it a template by inserting ‘Template Name: frontpage’ as a comment at the front of the file.

    Get a copy of the original index.php and place it in your theme’s folder.

    Create a blank page for the front page unless you already have one, and assign the new frontpage template to it.

    Create a blank Blog page unless you already have a page named Blog.

    In Admin->Settings->Reading, choose the static front page option and assign your front page as Front page and Blog as the Posts page.

    Thread Starter lukewilde

    (@lukewilde)

    Is there not just some php i can enter in the blog.php file to get the posts? i tried what you said to do and after changing the index file name and getting another blank index.php my site just stopped working.

    I did not say a blank index.php, rather a copy of the original.

    The index.php file is the one that is used as the default template when no other template can be found. It may cause you trouble in the future if you do not use it for that.

    That being said, you can add code to the blog.php file to retrieve your posts. It is hard to say exactly what the code should be without seeing all of blog.php, but it should include the following:

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args = array(
       'paged' => $paged,
       'posts_per_page' => 10, //set this to the number of posts per page
       'caller_get_posts' => 0,  //set this to 1 to ignore sticky posts
    );
    query_posts($args);
    if (have_posts()) :
       while (have_posts()) :
          the_post();
          // rest of code to display a post
       endwhile;
    else :
       // code for no posts found
    endif;
    ?>
    Thread Starter lukewilde

    (@lukewilde)

    I dont really have an original index.php i just made mine the way it looks now, so i am not really sure how i can do this.

    I highly recommend that you read the following articles. They will give you a good introduction to creating a theme. WordPress provides a framework for a web site, but you need to follow the guidelines or you will run into trouble trying to use the features.


    https://codex.www.ads-software.com/Theme_Development

    https://codex.www.ads-software.com/Stepping_Into_Templates

    https://codex.www.ads-software.com/The_Loop_in_Action

    The last article contains a simple example of an index.php file.

    Thread Starter lukewilde

    (@lukewilde)

    Thanks a lot for your help, i changed the name to frontpage.php and made a simple index.php so i now have a home button which i was wondering how to do also.

    But now the blog page isn’t showing the title, date the post was made or anything, it only shows the text which is inside the post, i have tried it with and without a template assigned to the page and it makes no difference to the style it is being displayed in, what have i done wrong now ??

    Probably nothing wrong. The simple index.php in the article I cited only displays the content. It is meant to be a starting point for you to enhance with more code.

    Here is a link to a slightly more complete index.php. This one will show more than the content.

    You change the style of the posts with a style.css file, not with a template. The blog ignores a template and uses index.php.

    I think it would be a good idea if you found a good theme that is nearly what you want, and then made your static front page compatible with it. A theme will come with an index.php, a style.css, and other files that all fit together for a good starting point.

    I don’t know what look you are trying to achieve. If you post a link to your site, you might get some suggestions of themes to look at.

    Thread Starter lukewilde

    (@lukewilde)

    Ok then i will take a look into editing the index.php, i didnt realise i would need to include the title and date codes into the index, as i had done all of that inside the blog.php file i had made so i thought it would look at that as i have the blog page using the blog.php template.

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘Blog page’ is closed to new replies.