非插件实现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
- OLVPS→104 元 月 1GB 内存 50GB 空间 2TB 流量 虚拟空间(主机)
- 补货通知 VirMach→512M 套餐圣何塞补货 速度不错 部分 IP全球[VPS测评]
- ServerStadium→$13.5 月-Dual L5420 16G全球[VPS测评]
- spinservers 限时 48 小时闪购,美国双路 E5-2630L美国VPS[主机]
- LOCVPS→日本大阪 65 折 XEN 双核 2G 30GB 5M 每日本VPS[主机]
- Rabbithosts→4400 元 月 2 核 4GB 内存 20GB虚拟空间(主机)
- 劳动节秒杀 腾讯云→1 核 1G 1M 香港免备案套餐年付¥249 2 香港VPS[主机]
- NameSilo - 网站改版新 UI 新注册域名降价优惠全球[VPS测评]
- 碳氧云→80 元 月 6 核 6GB 内存 80GB SSD 空间 不限虚拟空间(主机)
- OneProvider→法国 荷兰独服特价 1Gbps 带宽 不限流量 全球[VPS测评]
- 搬瓦工 $29.88 年 2G 内存 40G SSD 1T 流量 KVM全球[VPS测评]
- 宝塔面板免费版如何开启 waf 防火墙全球[VPS测评]
- HostNamaste印度商家:美国/法国便宜KVM VPS 1核1G/美国VPS[主机]
- 使用测速脚本对国外VPS服务器进行测速全球[VPS测评]
- VPSnet.com立陶宛便宜vps,€1.99起/月-基于Virtuo全球[VPS测评]
- 如何为WordPress网站站外链接添加自动nofollow功能全球[VPS测评]
- WordPress禁用谷歌字体插件:Disable Google Fon全球[VPS测评]
- TPE海缆故障通报-完成修复全球[VPS测评]
- 什么是VPS?国内VPS有哪些?全球[VPS测评]
- 再“掷”53亿元 宜家能否挽回中国消费者全球[VPS测评]
- kvmcloud怎么样?香港BGP云服务器 月付12.9元香港VPS[主机]
- 青果云:香港云主机2核1G3M30G,香港vps仅售59元/月香港VPS[主机]
- 永恒云:江苏挂机宝6元/月,60元/年;香港建站vps仅18元;深圳BG香港VPS[主机]
- dogyun:2020国庆促销,7.1折优惠,多线路vps-香港CN2、日本VPS[主机]
- 六一云:国内BGP高防vps套餐,1核/1G/2Mbps/香港CN2,月香港VPS[主机]
- VPS到底有什么用?全球[VPS测评]
- 欧亚云:新春优惠,洛杉矶CERA云主机仅25元/月起,香港CN2仅28元香港VPS[主机]
- 买了一台云服务器到底能干什么?全球[VPS测评]
- tmhhost:香港CN2/NNT,美国CN2 GIA VPS,韩国CN韩国VPS[主机]
- 欧亚云:香港cn2 vps低至28元/月,支持Windows,系统盘数据WINDOWS
转载请注明原文地址:http://140.238.13.167:12355/read-142445.html











