• Resolved lbutler

    (@lbutler)


    I have a WP blog setup and I want to include on a different page (actually within a frame) the most recent post from the blog and ONLY the most recent post. I can’t figure out how to get a link to the most recent post though without manually updating every time.

Viewing 6 replies - 1 through 6 (of 6 total)
  • create a file, put this in it:

    <?php
    include('PATH TO /wp-blog-header.php'); // <-- EDIT THAT SO THE PATH IS RIGHT
    define('WP_USE_THEMES', false);
    $my_query = new WP_Query('showposts=1');
    while ($my_query->have_posts()) : $my_query->the_post();
    ?>
    <?php the_excerpt(); ?><?php the_title(); ?><?php the_content(); ?>
    <?php endwhile; ?>

    More info in case above isnt quite right:

    https://codex.www.ads-software.com/Template_Tags/query_posts

    Please look at the codex to understand why I provided you with the_excerpt, the_content, the_title …

    Thread Starter lbutler

    (@lbutler)

    I found a answer that said to use

    <?php query_posts('name=first-post')?>

    But the trouble is I don’t know where to use that, so let me give more detail.

    SERVER1 has the blog. SERVER2 has a default page that has the login for the webmail in a top frame. In the bottom frame, I currently have a message about linking to the server status blog. Instead, I want to load the most recent post from that server status blog (hosted on SERVER1).

    So, I will need, I guess, the code to login to the mysql database and pull the the most recent post and then display it. SERVER2 doesn’t have WordPress installed, so I was hoping to be able to display something like an RSS feed of the most recent post instead of installing WordPress on SERVER2.

    Make sense?

    First off,

    you cant just make remote mysql connections to servers. You need to make sure the server thats going to accept the connection allows them.

    Most hosts do NOT allow that.

    Secondly, and only if you find that the first does allow that, then you will need to construct a stand-alone MySQL script to accomplish this. And for that, there are better resources — namely and specifically the MySQL forums.

    The other option is to simply use the feed, and for that, there are LOTS of stand alone php scripts that grab and parse feeds. Your best bet is to use google to find those.

    Another option is to use what I provided in an iframe on the the second site. Most decent browsers are going to have a fit over it though since its a cross-doamin iframe, but hey .. its your mess.

    Thread Starter lbutler

    (@lbutler)

    Thanks for the code. I put it in a file named single.php and put it in the root of the blog (with the wp-blog-header.php file). I get the following error:

    Fatal error: Class ‘WP_Query’ not found in /usr/local/www/single.php on line 4

    [EDIT: never mind, I removed the leading slash from /wp-blog-header.php and it loads fine. Thank you! ]

    … edit the file ??

    Its amazing how easily people copy and paste without reading.

    What if it said:

    <?php
    exec("I just cant do it");
    ?>
    Thread Starter lbutler

    (@lbutler)

    hey now, /wp-blog-header.php loads just fine (it loads a blank page, but hey) from the web site, so I was thinking web paths, not … you know, PATH paths ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to setup a page to show most recent post’ is closed to new replies.