B2主题文章内页点击展开更多

很久前的一个子主题中提取出来的,JUSTNEWS主题也有类似的功能,有需要可以在本站找找。

效果图

B2主题文章内页点击展开更多

功能上是可以增加网站的PV,但是之前百度好像严打过这种按钮一次。

教程

将下面的代码放入你主题的functions.php中,可以放子主题。

//字数统计
function word_num () {
	global $post;
	$text_num = mb_strlen(preg_replace('/\s/','',html_entity_decode(strip_tags($post->post_content))),'UTF-8');
	return $text_num;
}

css代码

/*阅读全文*/
#contTab{
    display: none;
}
.content-more{
    display: none;
}
#contTab:checked ~ #cont{
    max-height: 1000px;
    overflow: hidden;
}
#contTab:checked ~  .content-more{
    display: block;
    position: relative;
    padding-top: 20px;
    padding-bottom: 30px;
    text-align: center;
}
#contTab:checked ~  .content-more .gradient{
    background-image: -webkit-gradient(linear,left top,left bottom,from(rgba(255,255,255,0)),to(#fff));
    background-image: -webkit-linear-gradient(top,rgba(255,255,255,0),#fff);
    background-image: linear-gradient(-180deg,rgba(255,255,255,0),#fff);
    height: 80px;
    position: absolute;
    left: 0;
    top: -79px;
    width: 100%;
}
#contTab:checked ~  .content-more .readmore{
    display: inline-block;
    background: #f44360;
    color: #fff;
    width: 175px;
    height: 42px;
    border-radius: 42px;
    line-height: 42px;
    font-size: 16px;
    cursor: pointer;
}

文章页的修改

找到

<?php the_content(); ?>

修改为

<?php if (word_num() > 250) { ?>
        <input type="checkbox" id="contTab" checked="checked" class="tabbed">
        <div id="cont">
        <?php the_content(); ?>
        </div>
        <div class="content-more"><div class="gradient"></div> <label for="contTab" class="readmore">点击展开全文</label></div>
        <?php } else { ?>
        <?php the_content(); ?>
        <?php } ?>
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索