wordpress二次开发教程手记:站外以HTML的形式调用wordpress文章

小V在帮客户开发wordpress站点时常常会遇到各类要求,此次帮一个客户开发项目时,客户要求帮他开发的站点的文章能在其余网站调用,而且要以HTML的形式来调用不能使用js,说是作链轮什么的。没办法顾客就是上帝,继续折腾呗。下面来讲下实现方法,首先在wordpress的根目录新建一个html_post.php文件,记住是须要向外调用文章的wordpress站点。html_post.php文件的代码以下: php

<?php define('WP_USE_THEMES', false); require('./wp-load.php'); query_posts('showposts=10&orderby=new'); ?> /** charset=UTF-8"防止乱码 */ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <?php while (have_posts()): the_post(); ?> <li><a title="<?php the_title(); ?>" href="<?php%20the_permalink();%20?>" target="_blank"><?php the_title(); ?></a></li> <?php endwhile; ?>

    这样就能够调用网站中最新的10篇文章了,showposts=10这个数字能够修改为你想要调用文章的数量。下面我来给你们仔细讲解下如何来修改代码达到调用本身想要调用文章的效果。 html

    一、若是我想要调用某个分类的下的最新文章该如何实现呢? wordpress

    其实这点很容易实现的只须要修改下query_posts这个参数,好比我指定要调用的分类的ID是1那么代码就变成了: post

<?php define('WP_USE_THEMES', false); require('./wp-load.php'); /** 若是想同时调用多个分类用半角符分隔如cat=1,2,3,4 */ query_posts('showposts=10&orderby=new&cat=1'); ?> /** charset=UTF-8"防止乱码 */ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <?php while (have_posts()): the_post(); ?> <li><a title="<?php the_title(); ?>" href="<?php%20the_permalink();%20?>" target="_blank"><?php the_title(); ?></a></li> <?php endwhile; ?>

二、若是我想调用全站站问斩但只屏蔽某个分类下的文章呢?

。。。。。 网站

完整原文:

原文链接:http://www.noobyard.com/article/p-ozqobwqu-dc.html

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享