dedecms调用WordPress数据方法
dedecms调用WordPress数据方法摘要内容:dedecms 直接调用WordPress数据的方法
dedecms 直接调用WordPress数据的方法
1、同一个站点的情况下。假设WordPress安装在blog目录下;
<?php
define('WP_USE_THEMES', false);
require('blog/wp-blog-header.php'); //修改博客的路径
query_posts('showposts=20'); //显示文章条数
?>
<?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; ?>
2、不在同一个站点下面
把上面的保存为blog_call.php;然后在你调用的地方加入以下代码
<?php
//$str = file("http://www.blog.com/blog_call.php");
//补充 file测试中有读取不全的现象更正为:
f$str = ile_get_contents("http://www.blog.com/blog_call.php");
echo $str[0];
?>
这个情况我测试了一下,有的时候不成功,如果不成功你用下面的语句
<?php
$ch = curl_init();
$timeout = 5;
curl_setopt ($ch, CURLOPT_URL, 'http://www.itfw5.com/blog_call.php');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
本文地址:http://www.itfw5.com/webdesign/cmspro/1659.html





发表评论