Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
主题wpexplorer Today主题上的Wordpress摘录字符限制_Wordpress_Wordpress Theming - Fatal编程技术网

主题wpexplorer Today主题上的Wordpress摘录字符限制

主题wpexplorer Today主题上的Wordpress摘录字符限制,wordpress,wordpress-theming,Wordpress,Wordpress Theming,我需要帮助修复今天的主题 frontpage框采用随机大小。我是如何把它从单词改成字符的。还有图像。非常感谢您的帮助。我不是编码员 /** * Custom excerpts based on wp_trim_words * Created for child-theming purposes * * @link http://codex.wordpress.org/Function_Reference/wp_trim_words * @since 1.0.0 */ functi

我需要帮助修复今天的主题

frontpage框采用随机大小。我是如何把它从单词改成字符的。还有图像。非常感谢您的帮助。我不是编码员

/**
 * Custom excerpts based on wp_trim_words
 * Created for child-theming purposes
 * 
 * @link  http://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 );

}
/**
*基于wp_trim_单词的自定义摘录
*创建子主题的目的
* 
*@linkhttp://codex.wordpress.org/Function_Reference/wp_trim_words
*@自1.0.0以来
*/
函数wpex_摘录($length=45,$readmore=false){
//获取全局post数据
全球$员额;
//检查自定义摘录
如果(有摘录($post->ID)){
$output=$post->post_摘录;
}
//没有自定义摘录…所以让我们生成一个
否则{
//红色文字
$readmore_text=get_theme_mod('entry_readmore_text',esc_html_('readmore','today');
//阅读更多链接
$readmore_link='';
//检查更多标记并返回内容(如果存在)
if(strpos($post->post_内容,')){
$output=获取内容(“”);
}
//没有定义更多标记,因此使用wp_trim_单词生成摘录
否则{
//生成摘录
$output=wp\u trim\u words(strip\u短代码(获取\u内容($post->ID)),$length);
//如果启用,将readmore添加到摘录
如果($readmore==true){
$output.=应用过滤器('wpex\u readmore\u link',$readmore\u link);
}
}
}
//应用过滤器和回波
回声应用过滤器('wpex_摘录',$output);
}

我为您编辑了它:

**
 * Custom excerpts based on wp_trim_words
 * Created for child-theming purposes
 * 
 * @link  http://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 );

}
**
*基于wp_trim_单词的自定义摘录
*创建子主题的目的
* 
*@linkhttp://codex.wordpress.org/Function_Reference/wp_trim_words
*@自1.0.0以来
*/
函数wpex_摘录($length=45,$readmore=false){
//获取全局post数据
全球$员额;
$max_字符=40;
//检查自定义摘录
如果(有摘录($post->ID)){
$output=mb_strimwidth($post->post_摘录,0,$max_字符,“…”);
}
//没有自定义摘录…所以让我们生成一个
否则{
//红色文字
$readmore_text=get_theme_mod('entry_readmore_text',esc_html_('readmore','today');
//阅读更多链接
$readmore_link='';
//检查更多标记并返回内容(如果存在)
if(strpos($post->post_内容,')){
$output=mb_strimwidth(获取内容(“”),0,$max_字符,“…”);
}
//没有定义更多标记,因此使用wp_trim_单词生成摘录
否则{
//生成摘录
$output_to_trim=wp_trim_字(strip_短码(获取_内容($post->ID)),$length);
$output=mb_strimwidth($output_to_trim,0,$max_个字符,“…”);
//如果启用,将readmore添加到摘录
如果($readmore==true){
$output.=应用过滤器('wpex\u readmore\u link',$readmore\u link);
}
}
}
//应用过滤器和回波
回声应用过滤器('wpex_摘录',$output);
}
通过更改$max_characters变量中的数字,可以更改此代码中的最大字符数

我使用了mb_strimwidth()函数并将其返回到$output变量:

通过示例,您应该了解发生了什么:

 <?php
echo mb_strimwidth("Hello World", 0, 10, "...");
// outputs Hello W...
?>

该函数需要类似“Hello World”的字符串、字符串开头(如0)、最大字符数(如10),并且在结尾可以选择摘录的好结尾(如…)