如何将用户描述限制为用户列表中的一定数量的字符?

时间:2015-11-03 16:38:31

标签: wordpress metadata

我正在改变我的"用户"的布局。 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">
		<?php the_title(); ?>
</div>
	<div id="blog-list" class="blog-category">
	<ul>	
		<?php

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

1 个答案:

答案 0 :(得分:1)

假设您的意思是尝试...

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

将返回150(您可以将其更改为您喜欢的)字符,并确保它也完成最后一个字。