• If I have a site that is www.mysite.com and the blog is in www.mysite.com/blog how can I put a blog post on the index.php page of the root (www.mysite.com/index.php)
    I want to display the most recent post on the root NOT on the blog site of www.mysite.com/blog
    I am having issues from PHP giving me fatal errors like Fatal error: Call to undefined function: single_post_title() in index.php on line 54 because when I use template tags on any other page but the WP template page an error like the one above happens.
    Do I need to call or include some code from the template into the other pages that I want to display WP elements?
    Thanx.
    Joe.

Viewing 5 replies - 1 through 5 (of 5 total)
  • I don’t know too much about this, but I think you do.
    At the very least, at the top of any page you want to use with wordpress, you need to include the following header:
    <?php
    $blog = 1;
    require('wp-blog-header.php');
    ?>
    …but only if the new page is in the same folder as the main index template. If not, you have to replace wp-blog-header.php with the full address (i.e., https://theurlofyourwebsite.com/wp-blog-header.php).
    The other thing you may have to implement is the main loop, if you’re using the page to show a bunch of entries. That is,
    <?php if ($posts) { foreach ($posts as $post) { start_wp(); ?>
    (Insert code for what you want to show for each post – title, content, etc.)
    <?php } } else { // end foreach, end if any posts ?>
    (Insert what you want to show when no posts match the passed criteria)
    <?php } ?>
    Hope this helps!

    Woops! Replace the second line of the first code snippet with the following:
    $blog = 1;
    (that should read: dollar-sign, then “blog” (no quotes), then ” = 1;” (no quotes again.)

    And, more mistakes. Bugger.
    Basically, anytime you see “$” you should put a dollar sign in it’s place. Apparently, the filter likes to decode special symbols and what-not.
    Sorry for the confusion, and the wasted space.

    Thread Starter superspiker

    (@superspiker)

    Thank you! Works great… for now, until I find a better way.
    Thanx for your help even if it took 3 posts ??
    Joe.

    That’s basically the best approach. Note that you can put overrides before the blog-header include to say pull up a specific post ($p=12) or just the most recent one… just look in blog-header for how it builds up the sql statement, and force whatever vars you need to get the right result (limit of 1, order by date desc, something like that…).
    You can also use the RSS feed to grab the latest article content as well — that works too. Just put an RSS aggregator as part of your homepage.
    -d
    https://www.chait.net

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Show WP Posts on different page than template?’ is closed to new replies.