WordPress.org

Support

Support » Plugins and Hacks » “Latest Post” on external PHP page hack?

“Latest Post” on external PHP page hack?

  • Was wondering if there is a hack which allows me to display the latest post title and author and an external php page outside of the script?

    Thanks,
    -King πŸ™‚

Viewing 15 replies - 1 through 15 (of 21 total)
  • Anyone? πŸ™

    “and an external php page” or “as an external php page” ?

    And is it an entry you wanna display or just meta data?

    I guess you mean to display latest post on an external page, written in php… The easiest way in my book is using some RSS-reading script, there’s a bunch of those out there.

    i use this one in in my website http://www.vietzon.com

    —————–

    <?php $posts = get_posts( “numberposts=5” ); ?>
    <?php if( $posts ) : ?>
    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>

    <span class=”date”><?php the_time(‘M d’); ?>:</span> ” title=”click here to more…”><?php the_title(); ?>
    <?php endforeach; ?>
    <?php endif; ?>

    —————–

    Thanks guys, I’m gonna try “cam_oai’s” code. Ill let you know how it goes πŸ™‚

    -King

    here is what i did:
    1. create a new php and add this two before <body>
    <?php
    require(‘blog/wp-blog-header.php’);
    require_once(“blog/wp-config.php”);
    ?>

    change the dir to the correct path.

    2. paste the code:

    <?php $posts = get_posts( “numberposts=5” ); ?>
    <?php if( $posts ) : ?>
    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>

    <span class=”date”><?php the_time(‘M d’); ?>:</span> ” title=”click here to more…”><?php the_title(); ?>
    <?php endforeach; ?>
    <?php endif; ?>

    that’s all. if you only paste the code and not the 2lines before <body> then it will not know “where to get the posts” πŸ™‚

    check out my http://www.vietzon.com . the code gets 5latest post πŸ™‚

    Thanks cam_oai, finally found spare time to give code a go and it works! πŸ™‚

    To extend latest posts, what do I have to call to get the “author” and “postlink (permalink maybe?)”

    Is it possible to export β€œLatest postsβ€? to another site? And in HTML?

    Unfourtunately you can’t. Its breaches security to insert code from foreign sites. Also HTML is a know as the output needs to be built before the page is loaded.

    Thanks,
    -King

    Heartless_King: if you have time, take a look at the themes. download one and play with it. i just rip off the index.php in the theme folder and then remove bit by bit.

    postlink: ” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?>

    author: <?php the_author() ?>

    somehow in can’t get the author-thing to work, not in my own index.php, but in the themes index is OK.

    Including wp-blog-header.php and wp-config.php in order to use regular WP functions is a bit gratuitous in this case.

    I penned together a basic PHP/mySQL query to handle it for my own site; you can see it here

    Hi all:

    Thanks…cam’s code works great for me. I’m in the first stages of implementing it(see http://diseducation.com/newsletter/lastpost.php) but I want to see if I can take it a step further.

    Can I get the most recent comment as well as the most recent post, and put it in an external page?

    Thanks for the help anyone…

    If you use an RSS aggregator (like my CG-FeedRead) to do the work, you could get the most recent post, or comment, or comment on a particular post, or anything else you can pick up via RSS. πŸ˜‰

    RSS has another advantage: so long as you are using a caching aggregator (CGFR does, and I think most of the decent ones do), then it is only an html include on pageload while it is cached. When the timer expires and it needs to refresh, it polls the WP site for the RSS, and gets what it needs. In any case, you never directly include WP in your page, and you certainly never directly hit a SQL database to look something up.

    Just IMHO, a much better way to approach the problem. πŸ˜‰

    -d

    thanks…I’ll give it a shot.

    Hey i cant get the actually permalink code from you guys on here because it turns the code into an actual code and makes a link on your text. any help?

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘“Latest Post” on external PHP page hack?’ is closed to new replies.
Skip to toolbar