在1个外部php页面上显示所有wp帖子


Display all wp post on 1 external php page

我需要知道当所有链接(指向任何特定帖子)在A页上点击时,如何显示wp内容,而不进入wordpress安装文件夹。

页面A&B在wordpress安装文件夹之外。

谢谢。

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

页面B(从页面.php)

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

您必须加载WP库。David Walsh展示了如何: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>';

我不知道你为什么要这样做,但祝你好运:)

正确的方法是使用API。。http://codex.wordpress.org/Plugin_API/Hooks_2.0.x

如果你想运行一个带有wordpress功能的脚本,你需要包括wp_config.php(也许还有一些其他东西——只需谷歌一下)