【问题标题】:How to limit a user description to a certain amount of characters in a user list?如何将用户描述限制为用户列表中的一定数量的字符?
【发布时间】:2015-11-03 16:38:30
【问题描述】:

我正在更改 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(); ?>

【问题讨论】:

    标签: wordpress metadata


    【解决方案1】:

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

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

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

    【讨论】:

    • 完美运行。谢谢西蒙。
    猜你喜欢
    • 2015-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-25
    • 1970-01-01
    • 1970-01-01
    • 2012-04-04
    相关资源
    最近更新 更多