Codilight主题绕过了通常的the_excerpt
有自己的版本:
inc/extras.php +26
:
if ( ! function_exists( \'codilight_lite_excerpt\' ) ) :
/**
* Get the except content limit by characters.
*
* @param string $characters
* @return string
*/
function codilight_lite_excerpt( $characters ){
// $characters = 160;
$excerpt = get_the_content();
$excerpt = preg_replace(" (\\[.*?\\])",\'\',$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, $characters);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = trim(preg_replace( \'/\\s+/\', \' \', $excerpt));
$excerpt = $excerpt.\'...\';
return \'<div class="ft-excerpt">\'. $excerpt .\'</div>\';
}
endif;
最重要的是,他们甚至没有使用“适当”的方法,通过操作或过滤器进行修改,以方便儿童主题。相反,他们用一个子句包装了自己的函数,以检查您是否编写了自己的函数,这允许您重写他们的函数。所以在你的
functions.php
您基本上需要复制它们的函数,并根据需要添加自己的代码。
添加到your-child-theme/functions.php
:
/**
* override the parent theme excerpt
*
* @param string $characters
* @return string
*/
function codilight_lite_excerpt( $characters ){
$excerpt = get_the_content();
$excerpt = preg_replace( " (\\[.*?\\])", \'\', $excerpt );
$excerpt = strip_shortcodes( $excerpt );
$excerpt = strip_tags( $excerpt );
$excerpt = substr( $excerpt, 0, $characters );
$excerpt = substr( $excerpt, 0, strripos( $excerpt, " " ) );
$excerpt = trim( preg_replace( \'/\\s+/\', \' \', $excerpt ) );
$excerpt = $excerpt . \'...\';
$excerpt .= "<br><button>Visit Site</button>";
return \'<div class="ft-excerpt">\' . $excerpt . \'</div>\';
}
获取元数据并构建实际的按钮代码,我将留给您。