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
- 香港云服务器对于建站有什么便捷的地方? 香港VPS[主机]
- WHMCS 8.1如何简化注册页面 全球[VPS测评]
- 云服务器能干什么?有几十种玩法?阿里云,腾讯云服务器如何购买? 全球[VPS测评]
- 菜单选中标记CSS3动画效果 全球[VPS测评]
- 云计算的大门依旧没向雷军敞开 全球[VPS测评]
- 精编案例丨游戏行业转型升级迫在眉睫,云计算助力打造下一代游戏体验 全球[VPS测评]
- 腾讯云香港轻量应用服务器 优惠活动最低月付仅24元 香港VPS[主机]
- wikihost微基主机服务,香港稳定虚拟主机8折,3.73元/月起,C 香港VPS[主机]
- LOCVPS,全新香港大浦CN2 VPS 2核4G内存3M仅54/月 香港VPS[主机]
- DMIT:香港/洛杉矶GIA等KVM VPS,黑五DMIT优惠码活动,稳 香港VPS[主机]
- 小欢互联:洛杉矶高防vps年付138元,香港CN2线路月付8元起,1核/ 香港VPS[主机]
- 好云:国内云服务器2核2G5M优惠,仅350元/年;香港/海外云服务器, 香港VPS[主机]
- RAKsmart促销活动:韩国服务器低价抢购,美国G口服务器低至$99, 韩国VPS[主机]
- UCloud海外节点vps活动:香港、台湾等全球14个机房1折起,最低仅 香港VPS[主机]
- tmhhost:香港安畅机房三网CN2 GIA VPS,月付45起;美国 美国VPS[主机]
- 桔子数据:香港CN2大带宽云服务器28元/月_1核/1G/10M带宽/C 香港VPS[主机]
- Ceraus:香港CN2云服务器,香港GIA VPS去程移动回程路线,月 香港VPS[主机]
- ucloud云主机怎么样?ucloud云服务器1核2G仅52元/年起;香 香港VPS[主机]
- 衡天云:香港/美国云服务器_1核2G首年301元起;海外虚拟主机低至15 美国VPS[主机]
- 樊云:香港cn2+美国cn2,36元/月起,9折优惠促销;云服务器+独立 独立服务器[U]
- anyhk:香港HGC云服务器,1核/256MB/5GB SSD/600 香港VPS[主机]
- pigyun:韩国CN2云服务器仅14元;香港CN2建站vps特惠+美国 韩国VPS[主机]
- Hyocloud:愚人节,特惠+预售,香港BGP VPS/大带宽/大流量 香港VPS[主机]
- 40火伞高压电爬坡更让企业用电于民 全球[VPS测评]
- 从阿里云七代云服务器,谈云计算四大趋势 全球[VPS测评]
- 春天的风最容易温暖心灵,适合朋友圈和抖音的12条文案 全球[VPS测评]
- 拼多多回应筹备跨境电商业务:不予置评 全球[VPS测评]
- Rustrot-深绿色UI电商网站模板HTML5框架 全球[VPS测评]
- HostKVM香港云地VPS,2核4G内存折后$8.4/月,30M大带宽 香港VPS[主机]
- 香港vps免费:青云互联,1核1G/50G硬盘/500GB流量/2M带宽 香港VPS[主机]
转载请注明原文地址: http://140.238.13.167:12355/read-149449.html











