2015-11-03 14 views
0

我改變了我的「用戶」頁面的佈局WordPress的網站here如何將用戶描述限制爲用戶列表中的一定數量的字符?

我想說明的字符數限制爲一定的量,以「均衡」每個生物作者(用戶)。

可能嗎?

這裏的模板代碼:

<?php 
 

 
/* 
 
Template Name: Display Contributors and Authors 
 
*/ 
 

 
    $args = array(
 
     'role' => 'contributor', 
 
     'orderby' => 'post_count', 
 
     'order' => 'DESC' 
 
    ); 
 
    $contributors = get_users($args); 
 

 
    ?> 
 
    
 
<?php get_header();?> 
 
<div id="main"> 
 
<div id="primary" class="three-parts archive"> 
 
<div class="widget-title"> 
 
\t \t <?php the_title(); ?> 
 
</div> 
 
\t <div id="blog-list" class="blog-category"> 
 
\t <ul> \t 
 
\t \t <?php 
 

 
\t \t foreach($contributors as $contributor) 
 
\t 
 
\t { 
 
\t \t 
 
\t \t ?> 
 
\t \t <li style="margin-top: 10px; width:25%;"> \t 
 
\t \t \t <div class="blog-post-image"> 
 
\t \t \t \t <div class="image_fx5"> 
 
\t \t \t \t \t <a href=<?php echo get_author_posts_url($contributor->ID); ?>><?php echo get_avatar($contributor->user_email, '128'); ?></a> 
 
\t \t \t \t </div> 
 
\t \t \t </div> 
 
\t \t \t \t <!--author-image--> 
 
\t \t \t \t <div class="blog-post-title-box"> 
 
\t \t \t \t \t <div class="blog-post-title"> 
 
\t \t \t \t \t <h2> 
 
\t \t \t \t \t <a href=<?php echo get_author_posts_url($contributor->ID); ?>><?php echo $contributor->display_name; ?></a> 
 
\t \t \t \t \t </h2> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t </div> 
 
\t \t \t \t <!--author-name--> 
 
\t \t \t \t \t <div class="blog-post-content" style="padding-bottom: 0px; text-align: justify;"> 
 
\t \t \t \t \t <?php echo $contributor->description; ?> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t \t <div id="author-info" style="margin-top: 0px; padding-left: 0px; padding-right: 0px; border-bottom-width: 0px;"> 
 
\t \t \t \t \t <div id="author-desc" style="width: 100%;"> 
 
\t \t \t \t \t <ul class="author-social" style="padding-top: 0px;"> 
 
\t \t \t \t \t <?php if($contributor->facebook) { ?> 
 
\t \t \t \t \t <li style=" 
 
    margin-top: 0px; 
 
    padding-left: 0px; 
 
    padding-right: 0px; 
 
    height: 25px; 
 
"> 
 
\t \t \t \t \t \t <a href="http://facebook.com/<?php echo $contributor->facebook; ?>" class="fb-social-icon" target="_blank"> 
 
\t \t \t \t \t \t </a> 
 
\t \t \t \t \t </li> 
 
\t \t \t \t \t <?php } ?> 
 
\t \t \t \t \t <?php if($contributor->twitter) { ?> 
 
\t \t \t \t \t <li style=" 
 
    margin-top: 0px; 
 
    padding-left: 0px; 
 
    padding-right: 0px; 
 
    height: 25px; 
 
"> 
 
\t \t \t \t \t \t <a href="https://twitter.com/<?php echo $contributor->twitter; ?>" class="twitter-social-icon" target="_blank"> 
 
\t \t \t \t \t \t </a> 
 
\t \t \t \t \t </li> 
 
\t \t \t \t \t <?php } ?> 
 
\t \t \t \t \t <?php if($contributor->google) { ?> 
 
\t \t \t \t \t <li style=" 
 
    margin-top: 0px; 
 
    padding-left: 0px; 
 
    padding-right: 0px; 
 
    height: 25px; 
 
"> 
 
\t \t \t \t \t \t <a href="http://plus.google.com/<?php echo $contributor->google; ?>?rel=author" class="google-social-icon" target="_blank"> 
 
\t \t \t \t \t \t </a> 
 
\t \t \t \t \t </li> 
 
\t \t \t \t \t <?php } ?> 
 
\t \t \t \t \t <?php if($contributor->pinterest) { ?> 
 
\t \t \t \t \t <li style=" 
 
    margin-top: 0px; 
 
    padding-left: 0px; 
 
    padding-right: 0px; 
 
    height: 25px; 
 
"> 
 
\t \t \t \t \t \t <a href="http://www.pinterest.com/<?php echo $contributor->pinterest; ?>?rel=author" class="pinterest-social-icon" target="_blank"> 
 
\t \t \t \t \t \t </a> 
 
\t \t \t \t \t </li> 
 
\t \t \t \t \t <?php } ?> 
 
\t \t \t \t \t <?php if($contributor->instagram) { ?> 
 
\t \t \t \t \t <li style=" 
 
    margin-top: 0px; 
 
    padding-left: 0px; 
 
    padding-right: 0px; 
 
    height: 25px; 
 
"> 
 
\t \t \t \t \t \t <a href="http://www.instagram.com/<?php echo $contributor->instagram; ?>?rel=author" class="instagram-social-icon" target="_blank"> 
 
\t \t \t \t \t \t </a> 
 
\t \t \t \t \t </li> 
 
\t \t \t \t \t <?php } ?> 
 
\t \t \t \t \t </ul> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t \t <!--author-desc--> 
 
\t \t </li> 
 
\t \t \t <?php } ?> 
 
\t \t </ul> 
 
\t </div> 
 
</div> 
 
\t \t <!--primary--> 
 
\t <div id="secondary"> 
 
\t \t <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Category Sidebar')): endif; ?> 
 
\t </div> 
 
\t <!--secondary--> 
 
</div> 
 
<!--main--> 
 
<?php get_footer(); ?>

回答

1

假設你的意思是描述嘗試...

<?php echo substr($contributor->description, 0, strpos($contributor->description, ' ', 150)); ?> 

將返回150(你可以將其更改爲你喜歡)角色,並確保它完成最後一個單詞。

+0

工作完美。謝謝西蒙。 – Marco

相關問題