Reezal AQ
Reezal AQ

Reputation: 117

Display all wp post on 1 external php page

I need to know how to display wp content when all link (to any specific post) gets clicked on page A without going inside wordpress installation folder.

Both page A & B are outside wordpress installation folder.

THANK YOU.

PAGE A (main.php)

<?php /* Short and sweet */ define( 'WP_USE_THEMES', false); require( 'wordpress/wp-blog-header.php'); ?>

<div class="views-field-title">
  <?php query_posts( 'cat=5'); ?>
  <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  <span class="field-content"><a href="slave-page.php" rel="bookmark" title="Permanent Link to <?php  the_title_attribute(); ?>"><?php  the_title(); ?></a></span>
</div>

PAGE B (slave-page.php)

<?php /* Short and sweet */ define( 'WP_USE_THEMES', false); require( 'wordpress/wp-blog-header.php'); ?>


[place to display content]

Upvotes: 0

Views: 1366

Answers (2)

Steven
Steven

Reputation: 19425

You have to load the WP libraries. David Walsh shows how: http://davidwalsh.name/wordpress-recent-posts

// Include the wp-load'er
include('wp-load.php');

// Get the last 10 posts
// Returns posts as arrays instead of get_posts' objects
$recent_posts = wp_get_recent_posts(array(
    'numberposts' => 10
));

// Do something with them
echo '<ul>';
foreach($recent_posts as $post) {
    echo '<li><a href="', get_permalink($post['ID']), '">', $post['post_title'], '</a></li>';
}
echo '</ul>';

I don't know why you would want to though, but good luck :)

Upvotes: 1

Mike
Mike

Reputation: 781

The right way would be using the API.. http://codex.wordpress.org/Plugin_API/Hooks_2.0.x

If you want to run a script with wordpress functionalities you need to include wp_config.php (and maybe some other stuff - just google it)

Upvotes: 0

Related Questions