非插件实现WordPress侧栏最新文章列表+缩略图调用
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

如果是一般的WordPress主题,需要调用最新的文章列表至侧边栏直接拖动小工具就可以完成,即便有些主题不支持小工具我们也可以在侧边模板中手工添加最新的内容。但是,如果需要在侧边栏调用最新的内容且带有缩略图,要么可以用插件解决,要么采用无插件代码实现,这里蜗牛整理非插件实现WordPress侧栏最新文章列表+缩略图调用。
文章目录
隐藏
第一、代码部分
第二、样式部分
第一、代码部分<ul id=\\”new-posts\\”>
<?php
$recentPosts = new WP_Query();
$recentPosts->query(\\’showposts=10\\’); ?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
<li>
<?php
if ( has_post_thumbnail() ) {
?>
<a h=\\”<?php the_permalink(); ?>\\” title=\\”<?php the_title(); ?>\\”><?php the_post_thumbnail(\\’thumb\\’, array(\\’alt\\’ => \\’\\’.get_the_title().\\’\\’, \\’title\\’ => \\’\\’.get_the_title().\\’\\’)); ?></a>
<a class=\\”new-post-title\\” h=\\”<?php the_permalink(); ?>\\” title=\\”<?php the_title(); ?>\\”><?php the_title(); ?></a>
<?php } else {?> <a class=\\”new-post-title\\” h=\\”<?php the_permalink(); ?>\\” title=\\”<?php the_title(); ?>\\”><?php the_title(); ?></a>
<?php } ?>
<p>in <span class=\\”new-categ\\”><?php $category = get_the_category(); $categLink = get_category_link($category[0]->cat_ID); ?> <a h=\\”<?php echo $categLink; ?>\\” title=\\”<?php $category[0]->cat_name; ?>\\”><?php echo $category[0]->cat_name; ?></a></span></p>
</li>
<?php endwhile; ?>
</ul>
利用WP_Query函数调用最新的文章以及缩略图,前提是我们必须有缩略图的功能,这个我们自己添加就可以。
第二、样式部分需要定义样式部分,根据实际情况再做未调整。
#new-posts li { overflow:auto; margin:20px 0px;}
#new-posts li img { float:left; margin-right:10px; border:3px solid #798295;}
.new-post-title { text-decoration:none; font-weight:bold; color:#798295;}
.new-post-title:hover{color:#6eaebe;}
#new-posts li p { margin-top:10px; }
.new-categ{padding:5px;background:#6eaebe;}
.new-categ a{ font-weight:normal;color:#464b56;}
.new-categ a:hover{color:#545b68;}
这样我们可以看到调用的最新WORDPRESS内容且带有缩略图效果。
[WordPress教程]历史优惠活动内容
猜你可能想看的VPS
- MoonVM→$30 月 1GB 内存 10GB SSD 空间 3TB 虚拟空间(主机)
- Windows 系统怎么远程连接 Linux 云服务器-命令行模式WINDOWS
- Uovz→3500 元 年 L5630*2 8GB 内存 146GB S全球[VPS测评]
- CloudCone→$17.5 年 1.5GB 内存 45GB 空间 1虚拟空间(主机)
- iWFHosting→$8.99 月 KVM-2GB 25GB 1.5T全球[VPS测评]
- HostXen 预热双十一→充 300 送 100 续费减 10 元 新全球[VPS测评]
- Windows Server 2012 在桌面上显示”我的电脑”图标的方WINDOWS
- 新商家慎重-CombCloud→58 元 月 1GB 内存 20GB S香港VPS[主机]
- 疯狂猜成语 图猜成语两只金色的手在握手是什么成语?全球[VPS测评]
- HostUS→$6.45 月 4 核 1GB 内存 50GB SSD 空虚拟空间(主机)
- 不限内容大盘机 $38.5 年 1G 内存 1T 硬盘 10TB@1Gb全球[VPS测评]
- Centos 安装宝塔面板错误 提示 Python-pip instal全球[VPS测评]
- 腾讯云星星海 SA2 云服务器上线 1.2 折起,100%CPU 性能,全球[VPS测评]
- $3.5 月 1G 内存 50G 硬盘 1T 流量 1Gbps KVM 全球[VPS测评]
- 极光KVM香港Cera 1H1G30G硬盘CN2+BGP线路5m小带宽月香港VPS[主机]
- AcroServers 波兰商家,全球38个节点,默认1Gbps带宽,€全球[VPS测评]
- HAProxy 负载均衡配置全球[VPS测评]
- 美国-西雅图-Spartanhost-2.25刀 月-测评美国VPS[主机]
- 快速云:云服务器和vps区别是什么云服务器和vps哪个比较安全2022-全球[VPS测评]
- 因搜包耽误员工下班,苹果将支付3050万美元赔款全球[VPS测评]
- 私有云架设之优选拓普龙S465-24高密度存储服务器机箱评测解析全球[VPS测评]
- CMIVPS,香港vps终身八折$7.76/月起,1核1G内存,香港沙田香港VPS[主机]
- 六六云:美国cera机房CN2 GIA高防/香港CN2 GIA建站/CM美国VPS[主机]
- 速云互联:香港/美国CN2 GIA线路/BGP/10Mbps/全场八折,美国VPS[主机]
- 快云科技:2核2G3M香港云BGP/新界CN2云服务器,月付33元香港VPS[主机]
- 拼多多入局跨境电商平台,首站美国;奈雪的茶在上海建第二总部;pidan“美国VPS[主机]
- 腾讯云免备案海外服务器:高速网络免备案,助力企业出海!全球[VPS测评]
- 港口雄开万里流丨不出国门海淘全球青岛跨境电商未来可期全球[VPS测评]
- 云服务器都是有哪些特点?全球[VPS测评]
- anyhk:香港HGC/WTT/HKT线路、台湾HiNet线路NAT套餐香港VPS[主机]
转载请注明原文地址:http://140.238.13.167:12355/read-142445.html











