duanbishai5271
2013-04-19 07:24
浏览 32
已采纳

word wordpress后限制长度

Hi all I have a site in wordpress and I want to limit the character of the preview post different from default for example obnly 5 characters.

This is the piece of my content-category.php

<div class="entry-content">
    <?php 
    $excerpt = get_the_excerpt();
    if ( $use_excerpt == 'Content' ) {  
      the_content('<a style="margin-left: 5px;text-transform: uppercase;display: inline-block;" href="'. get_permalink($post->ID) . '"> '. __( 'Leggi Tutto' , 'color-theme-framework' ) .'</a>',true,'');
    }   
    else if ( $use_excerpt == 'Excerpt' && $excerpt != '' ){
      the_excerpt('',FALSE,'');
      echo '<a style="margin-left: 5px;display: inline-block;" href="' . get_permalink($post->ID) . '">' . __('Leggi Tutto', 'color-theme-framework') . '</a>';
    } ?>
</div><!-- entry-content -->

And this is the piece of functions.php of the excerpt that I have read is the function to limit the character but I don't have understand how change it to return only 5 characters intothe content for the preview of the news for example

/*=======================================
    Content Width and Excerpt Redeclared
=======================================*/
if ( !isset( $content_width ) ) 
    $content_width = 980;

// Remove rel attribute from the category list
function remove_category_list_rel($output)
{
  $output = str_replace(' rel="category"', '', $output);
  return $output;
}

add_filter('wp_list_categories', 'remove_category_list_rel');
add_filter('the_category', 'remove_category_list_rel');

remove_action( 'wp_head', 'feed_links_extra', 3 ); 
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'index_rel_link' );
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); 
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 );
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 );
remove_action( 'wp_head', 'wp_generator' );

add_theme_support( 'automatic-feed-links' );

function new_excerpt_length($length) {
    return 30;
}
add_filter('excerpt_length', 'new_excerpt_length');


function new_excerpt_more($more) {
    return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');

How can Ilimit the character of the preview of my news to 5 characters?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • duane9322 2013-04-19 07:44
    最佳回答

    Your code is using

    function new_excerpt_length($length) {
        return 30;
    }
    add_filter('excerpt_length', 'new_excerpt_length');
    

    The above code will limit excerpt to number of words and not characters.

    I found this answer from WordPress Stackexchange that has code to limit it with number of characters.

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题