怎样在外部调用WordPress文章

通过调用 wp-load.php 文件获取wordpress主要功能的。
wp-load.php加载了Wordpress本身和它所有的程序开发接口(API),装载后就可以在自己的程序中调用wordpress的函数。
博客网站根目录下创建php文件,此处命名为output.php。内容如下

1
2
3
4
5
6
7
8
9
10
<?php
// Include WordPress
define('WP_USE_THEMES', false);
require('./wp-load.php');
query_posts('showposts=10');
//这个调用最新文章,如果是热门文章的话则改为get_most_viewed("post",10),前提是你的主题安装了热门文章插件,而且此方法可以接受几乎wp-kit-cn所有代码。
?>
<?php while (have_posts()): the_post(); ?>
<li><a href="<?php the_permalink(); ?>" target="_blank"><?php echo mb_strimwidth(strip_tags(apply_filters('the_title', $post->post_title)), 0, 50," "); ?></a></li>
<?php endwhile; ?>

上面的代码可以输出文章标题
下面的代码则可以输出自定摘要

1
2
3
4
5
6
7
8
9
10
<?php
// Include WordPress
define('WP_USE_THEMES', false);
require('./wp-load.php');
query_posts('showposts=30');
?>
<?php while (have_posts()): the_post(); ?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php endwhile; ?>

在调用博客文章的地方插入以下代码,即可调用相应的内容

1
2
3
4
5
<?php
//把下面的地址改为你想引用的博客地址
$url="http://www.tdplayer.cn/wuli/output.php";
echo file_get_contents( $url );
?>

上面方法经测试可行,不像网上那些杂七杂八的冗长的代码还不能用。
本文转载:http://blog.crogram.org/415.html/comment-page-1

posted @ 2012-12-20 17:06  leeker  阅读(2820)  评论(0编辑  收藏  举报