全网影视免费看

WordPress美化教程-为文章内容页添加展开收缩功能

期初感觉不需要这方面的功能,最近突然发觉对于有些经常更新的文章来说,一下子太长的篇幅的确显得有些臃肿,在这个快速的信息时代来说,大多数人不喜欢太长篇大论的文章,所以说有时候折叠一部分内容显得还是很有必要的,用户可以选择查看自己感兴趣的内容,那么接下来结合本站实践来实现这一功能。

效果展示

添加代码

把下方代码添加到当前主题的footer.php文件中。

<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
<script>
/* 为wordpress主题添加“内容展开/收缩”功能开始 */
jQuery(document).ready(
function(jQuery){
jQuery('.collapseButton').click(function(){
jQuery(this).parent().parent().find('.xContent').slideToggle('slow');
});
});
/* 为wordpress主题添加“内容展开/收缩”功能开始 */
</script>

将下方代码添加至主题目录下的functions.php中

// 文章页添加展开收缩效果
function xcollapse($atts, $content = null){
extract(shortcode_atts(array("title"=>""),$atts));
return '
<style>.xControl {
font-size: 15px;
font-weight: bold;
padding: 5px 0;
box-shadow:0 0 20px #d0d0d0;/* 阴影 */
background-color: #FFFFFF;/* 背景颜色 */
border-bottom: 2px solid #e74c3c;/* 边 */
transition: all 0.1s linear;
text-align: center;
border-radius: 0 0 5% 5%;
border-radius:4px;
}
.xControl a{
text-decoration: none;
display: block;}
.xControl a:hover {
text-decoration: none;
display: block;
color:red;
}
.xControl i{font-style:normal;}
</style>
<div style="margin: 0.5em 0;">
<div class="xControl">
<a href="javascript:void(0)" class="collapseButton xButton"> <i class="fa fa-toggle-on" aria-hidden="true">&nbsp;</i><span class="xTitle">'.$title.'</span></a>
<div style="clear: both;"></div>
</div>
<div class="xContent" style="display: none;">'.$content.'</div>
</div>';
}
add_shortcode('collapse', 'xcollapse');

添加后台快捷按钮

把下面代码添加到主题目录下的functions.php,去掉第6行【collapse title=”点击展开 查看更多】前的斜杠 /

//添加展开/收缩快捷标签按钮
function appthemes_add_collapse() {
?>
<script type="text/javascript">
if ( typeof QTags != 'undefined' ) {
QTags.addButton( 'collapse', '展开/收缩按钮', '[/collapse title="点击展开 查看更多"]','[/collapse]' );
} 
</script>
<?php 
}
add_action('admin_print_footer_scripts', 'appthemes_add_collapse' );
本站福利,全网影视在线免费看 | 点击出发

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

提示:非实物交易,购买后不退款,请考虑好再购买 | 点此查看购买指南
售前咨询和售后服务,请点此联系作者咨询

给TA赞赏
共{{data.count}}人
人已赞赏
广告占位
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索