推广 热搜: 后台  位置  帝国cms  网站  Wordpress教程  帝国cms建站  内容  DESTOON  邮箱  destoon7.0 

wordpress站外以HTML的形式调用wordpress文章

   日期:2019-04-22     浏览:177    违规举报
 
腾讯云服务器优惠

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

<?phpdefine('WP_USE_THEMES', false);require('./wp-load.php');query_posts('showposts=10&orderby=new');?><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 the_permalink(); ?>" target="_blank"><?php the_title(); ?></a></li><?php endwhile; ?>

这样就可以调用网站中最新的10篇文章了,showposts=10这个数字可以修改成你想要调用文章的数量。下面我来给大家仔细讲解下如何来修改代码达到调用自己想要调用文章的效果。

1、如果我想要调用某个分类的下的最新文章该如何实现呢?

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

<?phpdefine('WP_USE_THEMES', false);require('./wp-load.php');query_posts('showposts=10&orderby=new&cat=1');?><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 the_permalink(); ?>" target="_blank"><?php the_title(); ?></a></li><?php endwhile; ?>

2、如果我想调用全站但只屏蔽某个分类下的文章呢?

<?phpdefine('WP_USE_THEMES', false);require('./wp-load.php');query_posts('showposts=10&orderby=new&cat=-1');?><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 the_permalink(); ?>" target="_blank"><?php the_title(); ?></a></li><?php endwhile; ?>

3、如果我想调用随机文章呢?

<?phpdefine('WP_USE_THEMES', false);require('./wp-load.php');query_posts('showposts=10&orderby=rang');?><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 the_permalink(); ?>" target="_blank"><?php the_title(); ?></a></li><?php endwhile; ?>

4、如果我想输出摘要呢?

<?phpdefine('WP_USE_THEMES', false);require('./wp-load.php');query_posts('showposts=10&orderby=rang');?><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 the_permalink(); ?>" target="_blank"><?php the_title(); ?></a><?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 200,"...",'utf-8'); ?></li><?php endwhile; ?>

下面站外来调用的方法:

<?php//该代码放置在需要调用文章内容和列表的地方$url='http://你的站点地址/html_post.php';echo file_get_contents( $url );?>

大功告成。上面介绍的方法都必须要在调用站点支持php的情况下才可行,如果调用站点支持asp的话只要把读取html_post.php的PHP代码用ASP重写一遍,但是如果是静态空间就只能用js来调用咯。

免责声明:
1、本站所收集的部分公开资料来源于互联网,转载的目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。
2、本站部分作品内容是由网友自主投稿和发布、编辑整理上传,对此类内容本站仅提供交流平台,不为其版权负责,更不为其观点承担任何责任。
3、因行业及专业性有限,故未能核验会员发布内容的真实性及有效性,不为其负责,如有虚假或违规内容敬请准备材料图片发邮件到info@n360.cn举报,本站核实后积极配合删除。
4、如果您发现网站上有侵犯您的知识产权的作品,请与我们取得联系,我们会及时处理或删除。
 
打赏
 
更多>同类网站技术
0相关评论

推荐图文
推荐网站技术
点击排行
网站首页  |  关于我们  |  联系方式  |  使用协议  |  免责声明  |  版权隐私  |  信息发布规则  |  网站地图  |  排名推广  |  广告服务  |  积分换礼  |  网站留言  |  RSS订阅  |  违规举报  |  粤ICP备2020081222号
Powered By DESTOON