homepage Welcome to WebmasterWorld Guest from 54.197.108.124
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / WordPress
Forum Library, Charter, Moderators: lorax & rogerd

WordPress Forum

    
How to link to recent posts from main website outside wp
abhainn




msg:4508115
 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




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

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




msg:4508605
 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




msg:4509172
 2:47 am on Oct 18, 2012 (gmt 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:

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;
}

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / WordPress
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved