Grow your CSS skills. Land your dream job.

Latest Blog Post On Homepage?

  • # January 2, 2011 at 6:40 am

    I have a WordPress Homepage and a Blog Page. Somehow I would like to have the latest/most recent blog post to be on the homepage. I tried googling and inserting a few php codes but none seemed to work.

    Anyone know of a quick tutorial or solution to this?

    # January 2, 2011 at 10:22 am

    I’m assuming I could use this php code and reference that… if it’s the homepage, display recent post.


    < ?php if { is_home(); ?>

    ...get recent post

    whatever, i can’t code php, but you get my point.

    # January 2, 2011 at 10:57 am

    You could just use query_posts within that if statement at the start of your loop, or you could use a custom loop for index.php and use it in there:

    < ? php query_posts('posts_per_page=1'); ?>
    
    
    			
    		
    # January 2, 2011 at 10:58 am

    By the way I really recommend chris’s book diggin into wordpress, it explains this in there. The PDF copy is only $27 and well worth it if you’re considering using wordpress on a regular basis.

    # January 2, 2011 at 11:05 am

    Here’s my problem though, my index.php is for domain.com/blog and not domain.com. So if I change anything to the index.php file, it changes the blog page. Would I have to create a seperate php file for my home page or?

    I have these pages made on wordpress

    -Home (My “front page”)
    -Blog (Where My Blog Posts are set at on my settings)
    -Services (Services Page)
    -Portfolio (Portfolio Page)
    -Contact (Contact Page)

    # January 2, 2011 at 11:22 am

    I always prefer the second option, someone else might be able to advise you better on a way to achieve it using the first way though. One option could be to pull the latest post using RSS, although there may be a better way.

    # January 2, 2011 at 11:33 am

    Thanks. Basically I want exactly how @ChrisCoyier has his set up on his personal website’s homepage and blog.

    He has his latest post on the homepage AND a blog page for multiple posts.

    I should mention I put my wordpress files in a folder called “wordpress” so I had to copy the index.php file (below) to my root directory.



    < ?php
    /**
    * Front to the WordPress application. This file doesn't do anything, but loads
    * wp-blog-header.php which does and tells WordPress to load the theme.
    *
    * @package WordPress
    */

    /**
    * Tells WordPress to load the WordPress theme and output it.
    *
    * @var bool
    */
    define('WP_USE_THEMES', true);

    /** Loads the WordPress Environment and Template */
    require('./wordpress/wp-blog-header.php');
    ?>
    # January 2, 2011 at 12:02 pm

    Here is a visual.

    # January 2, 2011 at 12:11 pm

    ahh, what you need to do is the query posts as Johnny suggested and create a separate page for your homepage and your blog, page-slug.php, slug being the title of the page, created in wp admin, then have your index be a basic loop, with links to header and footers as index.php is mainly a fallback if there isn’t any other pages for them to use, so if there isn’t a single.php, or a page.php, they fall back to index.php. check out template hierarchy here:

    http://codex.wordpress.org/Template_Hierarchy

    # January 2, 2011 at 12:38 pm

    I found an alternate way to do this without creating custom pages.

    I installed “inline posts” plugin for wordpress.

    This way I just enter “post ID” in my home page and it pops up. The only downside is I will have to do this for every post I create. The upside is, it only takes 30 seconds.

    But if someone wants to make the process more clearly for others, it is much appreciated!

    # January 2, 2011 at 2:27 pm

    that works also^^

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".