教你如何通过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文件恶意代码清除方法
声卡驱动正常但是没有声音如何办?声卡驱动正常没声音的解决方法
英伟达显卡驱动如何退回到原来版本?英伟达显卡驱动退回到原来版
重装系统,电脑只有一个C盘如何创建分区
Defender提示错误应用程序MsMpEng.exe无法启动
电脑无法启动或仍在加载如何办?电脑无法启动或仍在加载的解决方
打印机驱动如何卸载删除?卸载打印机驱动干净的教程
电脑没网如何安装网卡驱动?教你没网如何安装网卡驱动的方法
系统32位和62位如何选择:详解它们之间的差异
电脑文件删不掉如何办?四种方法解决
任务管理器快捷键有哪些?任务管理器快捷键大全