DEDECMS调用WordPress最新文章和随机文章的方法

DEDECMS调用WordPress最新文章和随机文章的方法,解决两种程序之间相互沟通

DEDECMS调用WordPress的文章标题的方法:

LOOP调用代码:

[cce]
{dede:loop table=’wp_posts’ sort=’post_date’ row=’20′ if=”}<br>
<a href=”[field:guid/]“> [field:post_title/]</a> <br />
{/dede:loop}
[/cce]

SQL调用方法:

[cce]
{dede:sql sql=’Select * from wp_posts order by post_date desc limit 0,20′}
<li><a href=’[field:guid/]‘ target=’_blank’>[field:post_title/]</a></li>
{/dede:sql}
[/cce]

调用10条wordpress的最新文章(动态链接):

[cce]
{dede:sql sql=”SELECT * FROM wp_posts where post_status = ‘publish’ and post_type=’post’ order by post_date desc limit 0,10″}
<a href=’[field:guid/]‘ target=”_blank”>[field:post_title /]</a>
{/dede:sql}
[/cce]

随机调用10条wordpress的文章(动态链接):

[cce]
{dede:sql sql=”SELECT * FROM wp_posts where post_status = ‘publish’ and post_type=’post’ order by rand() desc limit 0,10″}
<a href=’[field:guid/]‘>[field:post_title /]</a>
{/dede:sql}
[/cce]

调用10条wordpress的最新文章(静态链接):

[cce]
{dede:sql sql=”Select id as post_id,post_title as post_title,post_type,post_date from wp_posts where post_type = ‘post’ order by post_date desc limit 0,10″}
<a href=’http://www.域名.com/blog/index.php/archives/[field:post_id /].html’ target=”_blank”>[field:post_title /]</a>
{/dede:sql}
[/cce]

随机调用10条wordpress的文章(静态链接):

[cce]
{dede:sql sql=”Select id as post_id,post_title as post_title,post_type,post_date from wp_posts where post_type = ‘post’ order by rand() desc limit 0,10″}
<a href=’http://www.域名.com/blog/index.php/archives/[field:post_id /].html’ target=”_blank”>[field:post_title /]</a>
{/dede:sql}
[/cce]
推荐使用SQL标签调用,因为简单而且生成的页面不含框架和JS等,对于SEO比较有利。

注意:

1.调用有一个前提:dede和wordpress必需共用同一个数据库。

2.代码中可能有全角字符,请注意修改后使用!(不然代码不起作用哦!)