Welcome to WebmasterWorld Guest from 54.147.44.93

Forum Moderators: rogerd & travelin cat

Message Too Old, No Replies

How to link to recent posts from main website outside wp

     

abhainn

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



Hi,

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


<ul>
<?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(); ?>
</ul>


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...

T.

lorax

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

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



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

[codex.wordpress.org...]

In particular I used the Grab The Header, The Loop and Examples sections.

abhainn

9:31 pm on Oct 16, 2012 (gmt 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.

tlainevool

2:47 am on Oct 18, 2012 (gmt 0)

10+ Year Member



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:

require('wp-blog-header.php');

function getHeadlines() {
get_currentuserinfo();

$i = 0; if ( have_posts() ) : while ( have_posts() && $i < 4 ) : the_post();
echo "<a href='";
the_permalink();
echo "'>";
the_title();
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='";
the_permalink();
echo "'>[more]</a><br/><br/>";

$i++; endwhile; endif;
}
 

Featured Threads

Hot Threads This Week

Hot Threads This Month