treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] Having WP Posts on Home page as well as blog page

  • I'm having a bit of trouble. I mocked up a site that has 2 post from its blog on the home page. but i want it so that the blog actally lives on its blog page. if that makes any since. Its very simalry to elliot jay stocks home page. He has on there recently from his blog. and then when you click blog. It has his blog with out all the other junk from the home page. If you check out his page im sure it will make a more since what im talk ing about.

    http://elliotjaystocks.com/
  • ok, well you have to have this php in your main index page or the one you want the wordpress to go into:

    this must be the very first thing in your php file

    <?php
    // Include Wordpress
    define('WP_USE_THEMES', false);
    require('/your_servers_script_address/blog/wp-blog-header.php');
    query_posts('showposts=1');
    ?>


    and have this in your page somewhere

    <!-- mini loop for the excerpts -->
    <?php while (have_posts()): the_post(); ?>
    <h2><?php the_title(); ?></h2>
    <?php the_excerpt(); ?>
    <p><a href=\"<?php the_permalink(); ?>\" class=\"red\">Read more...</a></p>
    <?php endwhile; ?>
    <!-- end the mini loop -->


    that is an excerpt from your last post
  • Ok i did what you said however its not really working. Here check it out

    The website is maddesignskillz.com
    and the blog is at maddesignskillz.com/blog

    The blog post is suppose to go right under the text talking about who they are.
  • I hope you used your scripting path???
    <?php
    // Include Wordpress
    define('WP_USE_THEMES', false);
    require('/your_servers_script_address/blog/wp-blog-header.php');
    query_posts('showposts=1');
    ?>


    in this line you must have your own scripting path, I just added in dubiuos text: require('/your_servers_script_address/blog/wp-blog-header.php');

    it might actually look something like the following but remember this is something like mine, although not exactly:require('/home/fhlinux172/w/abc.co.uk/user/htdocs/blog/wp-blog-header.php');

    so find out what your exact scripting path is and make sure you take it all the way to the wp-blog-header.php


    Ah..... this is your problem:
    Warning: require(/public_html/blog/wp-blog-header.php) [function.require]: failed to open stream: No such file or directory in /home/mad/public_html/wp-content/themes/starkers/index.php on line 4

    I will explain:
    you have this in your code:
    require(/public_html/blog/wp-blog-header.php)

    but your server is looking for this:
    require(/home/mad/public_html/wp-content/themes/starkers/index.php)

    now I don't know how you set up your wordpress but I would guess you have it on your main server at root level and not within its own directory the way I have mine, so I guess you will need:
    require(/home/mad/public_html/wp-blog-header.php)

    have a lok at your wordpress foot code on your index.php what is the path to that? this should explain why it is not working. However, remember make sure it is to your wp-blog-header.php
  • Thanks man I got it working
  • well done, you just need to style it to make it fit your design