WordPress the_excerpt()函数文章摘要字数并加上链接
the_excerpt()函数对于数字控制与给摘要带连接的技巧,希望此文章对各位会有所帮助.
WordPress里显示文章摘要的函数the_excerpt()默认是显示55个字,对于一些模板来说,只显示55个字的摘要貌似有些短,因此我们有必要在模板函数functions.php里面对the_excerpt()做个改造,使之按着我们的需求来展示更多(或更少)的摘要,改动很简单,在functions.php里加上这么一段即可:
function emtx_excerpt_length( $length ) { return 92; //把92改为你需要的字数,具体就看你的模板怎么显示了。 } add_filter( 'excerpt_length' , 'emtx_excerpt_length' );上面的只是对数字控制了,那么要如何给字符带上链接地址呢.处理方法很简单,我们只要往主题的functions.php里加上这么一段代码:
function emtx_continue_reading_link() { return ' <a href="' . get_permalink() . '">查看全文→</a>' ; } function emtx_auto_excerpt_more( $more ) { return ' …' . emtx_continue_reading_link(); } add_filter( 'excerpt_more' , 'emtx_auto_excerpt_more' ); function emtx_custom_excerpt_more( $output ) { if ( has_excerpt() && ! is_attachment() ) { $output .= emtx_continue_reading_link(); } return $output ; } add_filter( 'get_the_excerpt' , 'emtx_custom_excerpt_more' );查看更多关于WordPress the_excerpt()函数文章摘要字数并加上链接的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did9013