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
- 德国 CN2 GIA SaltyfishTech→1 核 1G 30G 全球[VPS测评]
- WinRAR 默认压缩为 ZIP 格式 设置鼠标右键菜单 WinRar 全球[VPS测评]
- 腾讯内部单边拥塞算法 BBR-TCPA 一键脚本安装及速度测评全球[VPS测评]
- 6yun→45 元 月 256MB 内存 5GB 空间 2TB 流量 1虚拟空间(主机)
- 劳动节 搬瓦工→新增 10Gbps 带宽的 cn2 gia 线路 VPS全球[VPS测评]
- $49 年 512M 内存 80G 硬盘 500G 流量 1Gbps K全球[VPS测评]
- Hostsailor→$28.8 月-E3 1231v3 8GB 1TB全球[VPS测评]
- 促销 RackNerd→st. patrick’s day 活动 2 核全球[VPS测评]
- MoeVM→$5.99 月 256MB 内存 10GB 空间 50GB 虚拟空间(主机)
- 数脉科技→365 元 月-E3 1230v2 16GB 1TB 10M 香港VPS[主机]
- [国庆]KVMLA→日本 新加坡 KVM 主机 8 折+赠送内存日本VPS[主机]
- 搬瓦工 2020 年最新优惠码,终身优惠 6.58%,高质量美国 cn2美国VPS[主机]
- 便宜 35 元 月 512M 内存 10G SSD 1000G 流量@1全球[VPS测评]
- 按小时计费 80M 主机→香港沙田机房 CN2 GIA 线路 年付低至 香港VPS[主机]
- WordPress博客网站搜索引擎优化需要注意几个SEO细节全球[VPS测评]
- CentOS/Fedora/Ubuntu/Debian 一键安装 wge全球[VPS测评]
- XIU 主题在首页最新发布文章标题后添加 NEW 图标 XIU 主题美化全球[VPS测评]
- 欧路云加拿大/法国/新加坡OVH高防VPS云服务器五折优惠 不限流量/1全球[VPS测评]
- RackNerd AMD Ryzen便宜VPS促销,NVMe硬盘,月付$全球[VPS测评]
- sunucucenter 2.4$ 月 土耳其 1C3G40G硬盘 无限全球[VPS测评]
- BaseZap-7.3$ 月 印度 1G内存25G硬盘 2T流量 虚拟服全球[VPS测评]
- 自适应bootstrap左侧导航可关闭全球[VPS测评]
- 2022年亚马逊Prime会员日将于7月12日和13日举行,覆盖24个站全球[VPS测评]
- 磐逸云怎么样?香港沙田cn2vps 带宽5M年付128元香港VPS[主机]
- 蓝米云:美国cera vps/香港cn2vps套餐,1核2G/40G/1美国VPS[主机]
- 详细介绍vps云服务器及其作用全球[VPS测评]
- 印象云,香港安畅CN2VPS终身8折1核1G22元/月,美国CN2高防V美国VPS[主机]
- edgeNAT:便宜美国CN2/香港CN2/韩国CN2低至48元/月_不韩国VPS[主机]
- 恒创科技:香港免备案CN2线路VPS/美国CN2直连VPS,月付28元起美国VPS[主机]
- 漂亮的Css3响应侧边栏菜单,动画风格侧边栏导航菜单样式全球[VPS测评]
转载请注明原文地址:http://140.238.13.167:12355/read-128232.html











