Welcome to WebmasterWorld Guest from

Forum Moderators: rogerd & travelin cat

Message Too Old, No Replies

How to link to recent posts from main website outside wp

10:49 am on Oct 15, 2012 (gmt 0)

New User

joined:May 28, 2012
votes: 0


I'm trying to display a list of the most recent wordpress posts on my main website. I can find a php code to do this, but it assumes the wp files are at the document root, which they are not - they are in a database on the same server, but not under the same document root. I don't know how to specify the correct path, I don't even know if it is possible.

Could anyone help, please?

This is the code

<?php require($_SERVER['DOCUMENT_ROOT'] . '/document-root/etc/etc/wp-load.php'); query_posts('showposts=3'); if (have_posts()) : while (have_posts()) : the_post(); ?>
<li> <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
<span>Posted on <?php the_time('l jS F, Y') ?></span><br />
<?php the_excerpt(); ?> </li>
<?php endwhile; else: echo "no posts"; endif; ?>
<?php wp_reset_query(); ?>

Document root: /webspace/httpdocs/mywebsite/
Database: /webspace/siteapplications/0000/
File I need the path to: /webspace/siteapplications/0000/htdocs/wp-load.php

After a lot of searching it looks to me that I might need to specify the path in the form of /var/www/ but I still don't know how to change the
<?php require($_SERVER['DOCUMENT_ROOT']

Am I going the right direction, or completely lost, please?

Thanks a million...

7:54 pm on Oct 15, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lorax is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Mar 31, 2002
votes: 0

This is the documentation that I used to do it for my own sites:


In particular I used the Grab The Header, The Loop and Examples sections.
9:31 pm on Oct 16, 2012 (gmt 0)

New User

joined:May 28, 2012
votes: 0

Thanks, I've been through it. My problem seems to be with php so moving on to try an understand it little better.

Thanks a million.
2:47 am on Oct 18, 2012 (gmt 0)

New User

10+ Year Member

joined:Apr 27, 2005
posts: 22
votes: 0

Here is code I wrote a long long time ago to do just that. Warning, it isn't great code, but it still seems to work just fine:


function getHeadlines() {

$i = 0; if ( have_posts() ) : while ( have_posts() && $i < 4 ) : the_post();
echo "<a href='";
echo "'>";
echo "</a> - ";
$excerpt = get_the_excerpt();
$pos = strpos($excerpt,".");
if( $pos !== false ) {
$excerpt = substr($excerpt,0,$pos + 1);
if (strlen($excerpt) > 80) {
$excerpt = substr($excerpt,0,80);
echo $excerpt;
echo "<a href='";
echo "'>[more]</a><br/><br/>";

$i++; endwhile; endif;

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members