教你如何通过wordpress文章id调用多篇文章


WordPress通过连续的文章ID输入来调用几篇固定文章内容,这个方法非常适合刚入门的wordpress主题制作和开发新手,简单方便易用轻易就能达到很满意的定制效果,只要需要输入id用英文半角逗号分隔一下就可以连续的展示文章内容,下面测速网把这段代码分享出来,需要的老铁可以直接复制粘贴来用,这个功能在主题的制作中是非常实用的。比如可以用在hot文章内,或是侧边框的焦点文章又或是文章末尾的指定推荐。

下面的循环代码添加在需要的位置即可,DIV属性和函数根据您的个人主题情况添加或删除

1234567891011121314<?php $posts = get_posts("numberposts=4&post_type=any&include=1,3,4,6"); if($posts) : foreach( $posts as $post ) : setup_postdata( $post ); ?><li><h2><a title="<?php the_title();?>" href="<?php%20the_permalink();%20?>" target="_blank"><?php the_title();?></a></h2><div ><a title="<?php the_title();?>" href="<?php%20the_permalink();%20?>"><?php if((function_exists('has_post_thumbnail')) && (has_post_thumbnail())){$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()) );?><img src="<?php%20echo%20$thumbnail_src[0];?>"/><?php }else {?><img alt="<?php the_title();?>" src="<?php%20echo%20catch_that_image();%20?>"/><?php } ?></a></div><div ><p><?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 100,"……"); ?></p></div><div ><a title="<?php the_title();?>" href="<?php%20the_permalink();%20?>">测速网请看</a></div></li><?php endforeach; endif; ?>


上一篇:免插件给wordpress文章页面添加文章字体大中小调节

下一篇:wordpress主题functions.php文件恶意代码清除方法


Copyright © 2002-2019 测速网 www.inhv.cn 皖ICP备2023010105号
测速城市 测速地区 测速街道 网速测试城市 网速测试地区 网速测试街道
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!

热门搜索 城市网站建设 地区网站制作 街道网页设计 大写数字 热点城市 热点地区 热点街道 热点时间 房贷计算器