DUX主题添加首页显示顶置文章功能 支持只显示指定顶置分类文章
![]() | ![]() | ![]() | ![]() |
| 【性价之王】 | 【线路之王】 | 【价格之王】 | 【配置之王】 |
| 【免费之王】 | 【香港首推】 | 【梯子之王】 | 【独服之王】 |

上次在为DUX主题4.0以前版本添加首页显示置顶文章功能文章分享了一个转自@蝈蝈要安静的设置方法,那是基于官方4.0以上的版本提取的。其实在2018年农历新年年初,蜗牛也找一个朋友做过DUX主题的修改,也是想实现在DUX主题最新发布前显示顶置文章,并且支持设置只显示指定分类目录顶置文章。但代码也有不完善的地方,有需要的朋友可以试试,具体显示效果如下:
1、修改主题index.php在主题index.php文件当中的“<?php $args = array(‘ignore_sticky_posts’ => 1,”前面加入下面代码。’cat’ => 后面填写需要显示的顶置分类ID,关于如何查看分类ID可以查看此文章:https://www.wn789.com/15938.html#title-2。
<?php if ($paged==1) { ?> <?php $args = array( \'post__in\' => get_option(\'sticky_posts\'), \'cat\' => 68,//置顶分类ID \'ignore_sticky_posts\' => 0, ); if( _hui(\'notinhome\') ){ $pool = array(); foreach (_hui(\'notinhome\') as $key => $value) { if( $value ) $pool[] = $key; } $args[\'cat\'] = \'-\'.implode($pool, \',-\'); }if( _hui(\'notinhome_post\') ){ $pool = _hui(\'notinhome_post\'); $args[\'post__not_in\'] = explode(\"\\n\", $pool); } query_posts($args); ?> <?php get_template_part( \'excerpt-zd\' ); ?> <?php } ?>2、新建excerpt-zd.php新建一个excerpt-zd.php,我们只需要复制一份excerpt.php文件改名为“excerpt-zd”,然后用记事本打开把下面代码替换为原来代码,是全部替换哦。
<?php$ii = 0;while ( have_posts() ) : the_post(); $_thumb = _get_post_thumbnail(); $_excerpt_text = \'\'; if( _hui(\'list_type\')==\'text\' || (_hui(\'list_type\') == \'thumb_if_has\' && strstr($_thumb, \'data-thumb=\"default\"\')) ){ $_excerpt_text = \' excerpt-text\'; } $ii++; echo \'<article class=\"excerpt excerpt-\'.$ii. $_excerpt_text .\' excerpt-zd\">\'; if( _hui(\'list_type\') == \'thumb\' ){ echo \'<a\'._post_target_blank().\' class=\"focus\" h=\"\'.get_permalink().\'\">\'.$_thumb.\'</a>\'; }else if( _hui(\'list_type\') == \'thumb_if_has\' && !strstr($_thumb, \'data-thumb=\"default\"\') ){ echo \'<a\'._post_target_blank().\' class=\"focus\" h=\"\'.get_permalink().\'\">\'.$_thumb.\'</a>\'; } echo \'<header>\'; if( _hui(\'post_plugin_cat\') && !is_category() ) { $category = get_the_category(); if($category[0]){ echo \'<a class=\"cat\" h=\"\'.get_category_link($category[0]->term_id ).\'\">\'.$category[0]->cat_name.\'<i></i></a> \'; } }; echo \'<h2><a\'._post_target_blank().\' h=\"\'.get_permalink().\'\" title=\"\'.get_the_title().get_the_subtitle(false)._get_delimiter().get_bloginfo(\'name\').\'\">\'.get_the_title().get_the_subtitle().\'</a></h2>\'; echo \'</header>\'; echo \'<p class=\"meta\">\'; if( _hui(\'post_plugin_date\') ){ echo \'<time><i class=\"fa fa-clock-o\"></i>\'.get_the_time(\'Y-m-d\').\'</time>\'; } if( _hui(\'post_plugin_author\') ){ $author = get_the_author(); if( _hui(\'author_link\') ){ $author = \'<a h=\"\'.get_author_posts_url( get_the_author_meta( \'ID\' ) ).\'\">\'.$author.\'</a>\'; } echo \'<span class=\"author\"><i class=\"fa fa-user\"></i>\'.$author.\'</span>\'; } if( _hui(\'post_plugin_view\') ){ echo \'<span class=\"pv\"><i class=\"fa fa-eye\"></i>\'._get_post_views().\'</span>\'; } if ( comments_open() && _hui(\'post_plugin_comm\') ) { echo \'<a class=\"pc\" h=\"\'.get_comments_link().\'\"><i class=\"fa fa-comments-o\"></i>评论(\'.get_comments_number(\'0\', \'1\', \'%\').\')</a>\'; } echo \'</p>\'; echo \'<p class=\"note\">\'._get_excerpt().\'</p>\'; if( _hui(\'post_link_excerpt_s\') ) _moloader(\'mo_post_link\'); echo \'<span class=\"zd\">置顶</span>\'; echo \'</article>\';endwhile;3、修改main.css把下面代码加到main.css文件的最后面。
.excerpt { position: relative;}.excerpt .zd { position: absolute; padding: 0; right: -38px; top: -16px; display: block; width: 76px; height: 20px; line-height: 20px; background: #ff5e52; color: #fff; font-size: 14px; font-weight: 400; text-align: center; transform: rotate(45deg); transform-origin: 0% 0%;}@media (max-width:640px){ .excerpt-sticky header{text-indent:0px;position: unset;} .sticky-icon { position: absolute; padding: 0; right: -38px; left: auto; top: -16px; display: block; width: 76px; height: 20px; line-height: 20px; background: #ff5e52; color: #fff; font-size: 14px; font-weight: 400; text-align: center; transform: rotate(45deg); transform-origin: 0% 0%; }}DUX无限制版下载方法蜗牛789博客DUX无限制版本下载方案,使用微信扫描下面二维码关注蜗牛789微信公众号。注意是关注微信公众号, 微信公众号每天晚上推送当日热门促销活动。然后在微信公众号回复“DUX主题”即可获取下载链接。100%服务器下载版本,绿色无毒。
[DUX主题添加首页显示顶置文章功能]历史优惠活动内容
猜你可能想看的VPS
- 活动 HostXen→新用户购买云主机 赠送 20 元代金券 中国香港 日本VPS[主机]
- 疯狂猜成语 图猜成语一个人站在地上举着天空中的云彩是什么成语?全球[VPS测评]
- 劳动节 zji→香港服务器 348 元 月 cn2+BGP 网络 e5-香港VPS[主机]
- layer 子窗体关闭后向父窗体传值的办法全球[VPS测评]
- 腾讯云秒杀→个人上海云服务器年付 99 元起 企业用户 2C4G5M 三全球[VPS测评]
- 疯狂猜成语 图猜成语一个黑衣人堵着耳朵拎着一口金色的钟是什么成语?全球[VPS测评]
- 如何在WordPress博客实现历史上的今天的小功能全球[VPS测评]
- 如何在begin主题实现评论自动排第一全球[VPS测评]
- quadranet机房 独立服务器买二赠一,3G DDoS高防,$39起独立服务器[U]
- WordPress代码实现自动为文章中的图片添加alt、title属性全球[VPS测评]
- WordPress无插件自动实现标签关键字内链全球[VPS测评]
- VPS4You → 1.8$ 月付 匈牙利 1C512MB5G硬盘 40全球[VPS测评]
- ConoHa 新加坡小鸡评测 不能看 Netflix全球[VPS测评]
- hostEONS 1核心 256M内存 5G SSD 100M不限流量 全球[VPS测评]
- 限量! 咸鱼云 → 圣何塞 Elite 9929 → 512M内存 8全球[VPS测评]
- kvmcloud怎么样?香港BGP云服务器 月付12.9元香港VPS[主机]
- 用玩客云做打印服务器,让你在手机上轻松实现无线打印全球[VPS测评]
- 深圳市城市交通规划设计研究中心股份有限公司关于与腾讯云计算(北京)有限责全球[VPS测评]
- 二三互联,香港cn2云服务器5折+85折双重优惠,稳定不限流量,1核1G香港VPS[主机]
- 野草云怎么样?香港、美国圣何塞高防VPS 1核1G3M 月付19元美国VPS[主机]
- edgeNAT:全场6折优惠,韩国CN2、美国CN2、香港CN2月付36韩国VPS[主机]
- 1分钟快速读懂云计算全球[VPS测评]
- OneTechCloud易科云双十二优惠:香港/美国CN2全场VPS季付美国VPS[主机]
- 傲闪云vps,1核1G低至10元起,国内高防/香港CN2/美国CN2/美美国VPS[主机]
- PQhosting:香港HE/乌克兰/俄罗斯/荷兰/摩尔多瓦vps主机/香港VPS[主机]
- 中国跨境电商,如何掘金欧洲市场?全球[VPS测评]
- 江苏高防服务器哪里买?宿迁BGP、宿迁双线高防服务器的价格全球[VPS测评]
- HostKvm:香港国际/美国洛杉矶七折优惠,其它业务全场八折,适合做站美国VPS[主机]
- 修罗云:1核/512MB/6GB空间/1TB流量/NAT/KVM/香港H虚拟空间(主机)
- CIO和其他IT领导者充分利用边缘计算增强业务的4个关键全球[VPS测评]
转载请注明原文地址:http://140.238.13.167:12355/read-134593.html











