
安装在同一目录的wordpress博客的数据库是可以相互调用的。也就是实现A博客调用B博客的最新文章功能。
<?php$con = mysql_connect('localhost', 'wentong_wp', 'xxxxxxxx',true);mysql_query("SET NAMES 'utf8'");mysql_select_db('dantezhu_t',$con);$result = mysql_query("select * from wp_posts where post_status='publish' order by ID desc limit 1;");$row = mysql_fetch_array($result);if ($row){ echo '<a href="/luxun" target="_blank">'; echo $row['post_content'] . "(".$row['comment_count'].")"; echo '</a>';}mysql_close($con);?>
注意1:
$con = mysql_connect('localhost', 'wentong_wp', 'xxxxxxxx',true);
这里的wentong_wp是被调用的数据可,xxxx是用户名了,并且最后的参数一定要为true
注意2:
mysql_query("SET NAMES 'utf8'");
要记得设置字符集编码是utf8,才能够正确显示。
via
人吐槽 | 人点赞 |
发表评论