我需要帮助修复http://wpexplorer-demos.com/today/page/2/今日主题。
【主题wpexplorer Today主题的WordPress摘录字符限制】frontbox框采用随机大小。我如何解决从单词到字符的问题。还有图像。任何帮助PLZ真的很感激。我不是编码员。
/**
* Custom excerpts based on wp_trim_words
* Created for child-theming purposes
*
* @linkhttp://codex.wordpress.org/Function_Reference/wp_trim_words
* @since 1.0.0
*/
function wpex_excerpt( $length = 45, $readmore = false ) {// Get global post data
global $post;
// Check for custom excerpt
if ( has_excerpt( $post->
ID ) ) {
$output = $post->
post_excerpt;
}// No custom excerpt...so lets generate one
else {// Redmore text
$readmore_text = get_theme_mod( 'entry_readmore_text', esc_html__( 'read more', 'today' ) );
// Readmore link
$readmore_link = '<
a href="'. get_permalink( $post->
ID ) .'" title="'. $readmore_text .'">
'. $readmore_text .'<
span class="wpex-readmore-rarr">
&
rarr;
<
/span>
<
/a>
';
// Check for more tag and return content if it exists
if ( strpos( $post->
post_content, '<
!--more-->
' ) ) {
$output = get_the_content( '' );
}// No more tag defined so generate excerpt using wp_trim_words
else {// Generate excerpt
$output = wp_trim_words( strip_shortcodes( get_the_content( $post->
ID ) ), $length );
// Add readmore to excerpt if enabled
if ( $readmore == true ) {
$output .= apply_filters( 'wpex_readmore_link', $readmore_link );
}}}// Apply filters and echo
echo apply_filters( 'wpex_excerpt', $output );
}
#1我已经为你编辑过:
**
* Custom excerpts based on wp_trim_words
* Created for child-theming purposes
*
* @linkhttp://codex.wordpress.org/Function_Reference/wp_trim_words
* @since 1.0.0
*/
function wpex_excerpt( $length = 45, $readmore = false ) {// Get global post data
global $post;
$max_characters = 40;
// Check for custom excerpt
if ( has_excerpt( $post->
ID ) ) {
$output = mb_strimwidth($post->
post_excerpt, 0, $max_characters, '...');
}// No custom excerpt...so lets generate one
else {// Redmore text
$readmore_text = get_theme_mod( 'entry_readmore_text', esc_html__( 'read more', 'today' ) );
// Readmore link
$readmore_link = '<
a href="'. get_permalink( $post->
ID ) .'" title="'. $readmore_text .'">
'. $readmore_text .'<
span class="wpex-readmore-rarr">
&
rarr;
<
/span>
<
/a>
';
// Check for more tag and return content if it exists
if ( strpos( $post->
post_content, '<
!--more-->
' ) ) {
$output = mb_strimwidth(get_the_content( '' ), 0, $max_characters, '...');
}// No more tag defined so generate excerpt using wp_trim_words
else {// Generate excerpt
$output_to_trim = wp_trim_words( strip_shortcodes( get_the_content( $post->
ID ) ), $length );
$output = mb_strimwidth($output_to_trim, 0, $max_characters, '...');
// Add readmore to excerpt if enabled
if ( $readmore == true ) {
$output .= apply_filters( 'wpex_readmore_link', $readmore_link );
}}}// Apply filters and echo
echo apply_filters( 'wpex_excerpt', $output );
}
你可以通过更改$ max_characters变量中的数字来更改此代码中的最大字符数。
我使用了mb_strimwidth()函数并将其返回到$ output变量:https://secure.php.net/manual/pl/function.mb-strimwidth.php
通过示例, 你应该了解发生了什么:
<
?php
echo mb_strimwidth("Hello World", 0, 10, "...");
// outputs Hello W...
?>
该函数需要像” Hello World” 这样的字符串, 字符串的开头(如0), 最大字符数(如10), 最后你可以选择摘录的漂亮结尾(如… )。
推荐阅读
- WordPress特色图片请求返回未知
- WordPress按标签过滤帖子
- 使用kallyas-child主题的WordPress错误
- WordPress排队样式依赖项加载不正常
- powershell将计算机加入到AD域安全组,并输出日志
- Android技术分享| 自习室自定义View代替通知动画(完)
- 网络不可用怎么办(无法访问互联网怎么办?网络故障原因大起底)
- #私藏项目实操分享#云开发数据库有哪些常用操作
- 百度搜索中台海量数据管理的云原生和智能化实践