非插件实现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
- 便宜 Hostsailor→256M 内存套餐$6.6 年 1G 内存月全球[VPS测评]
- HostXen 香港四区上线 CN2 线路 自由 DIY 配置香港VPS[主机]
- [黑五]EtherNetservers 常规套餐 75 折 特价套餐年付全球[VPS测评]
- Hosteons→首付 8 折 免费升级套餐 KVM 或者 OpenVZ全球[VPS测评]
- Pyclouds→352 元 月 1GB 内存 20GB 空间 不限流量虚拟空间(主机)
- 腾讯云秒杀→单核 2G2M 三年 680 元 单核 2G1M 年付 19全球[VPS测评]
- 疯狂猜成语 图猜成语七个义字分开六个思字在一起是什么成语?全球[VPS测评]
- 消息 迪拜主机商 hostsailor 近期会接入 CN2 线路 抗投诉全球[VPS测评]
- 去掉 power by dedecms 的两种方法全球[VPS测评]
- 不限流量 FirstByte 夏季折扣→俄罗斯 美国 欧洲 VPS 五折美国VPS[主机]
- iWFHosting→2G 内存 KVM 每月 8.99 美元 洛杉矶高全球[VPS测评]
- BandwagonHost→$29.89 季 1GB 内存 20GB S虚拟空间(主机)
- 高德地图 点赞好司机 领现金红包全球[VPS测评]
- LOCVPS→56 元 月 KVM-2GB 30GB 600GB 圣何塞全球[VPS测评]
- OneVPS KVM VPS终身 75 折优惠码 日本VPS最低月付3.日本VPS[主机]
- 宝塔面板免费版如何开启 waf 防火墙全球[VPS测评]
- 极光KVM香港Cera 1H1G30G硬盘CN2+BGP线路5m小带宽月香港VPS[主机]
- 如何在百度云虚拟主机BCH上配置WordPress伪静态全球[VPS测评]
- 滴盾双十二东莞BGP独立服务器16核32G内存500G流量G口50m带宽独立服务器[U]
- 如何检测WordPress博客的访问速度?全球[VPS测评]
- 在博客中如何合理展示AdSense 广告全球[VPS测评]
- 咖啡主机2021开年 新上香港/美国CN2轻量KVM ¥46.8/季美国VPS[主机]
- TheGigabit → 8.9$月付 马来西亚 1c1g40g硬盘 1全球[VPS测评]
- HKServerSolution → 2G 内存 20G HDD 2T单全球[VPS测评]
- HTML5绿色有机食品电商网站模板 - Organtio全球[VPS测评]
- 游戏服务器是什么意思?游戏服务器可以用云服务器吗?全球[VPS测评]
- 无忧云怎么样?大连BGP德阳100G高防香港CN2VPS云服务器香港VPS[主机]
- 美国信贷市场的痛苦将不亚于上世纪70年代的通胀时期美国VPS[主机]
- 企鹅小屋:深港IPLC节点,0.25元/G流量,不用不花钱全球[VPS测评]
- MoeCloud:香港BGP云服务器,512MB内存/10GB空间/1T虚拟空间(主机)
转载请注明原文地址:http://140.238.13.167:12355/read-142445.html











