Skip to content

Commit

Permalink
Limit title length
Browse files Browse the repository at this point in the history
  • Loading branch information
onionwyl committed Aug 1, 2016
1 parent 772d7c8 commit 61f8f82
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
7 changes: 6 additions & 1 deletion functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ function chinese_excerpt($text, $lenth=40) {
function new_excerpt_more($excerpt) {
return "";
}
add_filter("excerpt_more", "new_excerpt_more");
add_filter("excerpt_more", "new_excerpt_more");
//自定义截断函数
function dm_strimwidth($str ,$start , $width ,$trimmarker ){
$output = preg_replace('/^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$start.'}((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'.$width.'}).*/s','\1',$str);
return $output.$trimmarker;
}
20 changes: 10 additions & 10 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
$query = new WP_Query("posts_per_page=5&category_name=".$cat_name);
while($query->have_posts()): $query->the_post();
?>
<li class="li"><a href="<?php the_permalink(); ?>" class="black14"><?php the_title(); ?></a><font class="grey10"><?php the_time("m-d"); ?></font></li>
<li class="li"><a href="<?php the_permalink(); ?>" class="black14"><?php echo mb_strimwidth(get_the_title(), 0, 33,"...","UTF-8"); ?></a><font class="grey10"><?php the_time("m-d"); ?></font></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
<!-- 选项卡1文字结束 -->
Expand Down Expand Up @@ -151,7 +151,7 @@
$query = new WP_Query("posts_per_page=5&category_name=".$cat_name);
while($query->have_posts()): $query->the_post();
?>
<li class="li"><a href="<?php the_permalink(); ?>" class="black14"><?php the_title(); ?></a><font class="grey10"><?php the_time("m-d"); ?></font></li>
<li class="li"><a href="<?php the_permalink(); ?>" class="black14"><?php echo mb_strimwidth(get_the_title(), 0, 33,"...","UTF-8"); ?></a><font class="grey10"><?php the_time("m-d"); ?></font></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
<!-- 选项卡2文字结束 -->
Expand Down Expand Up @@ -206,7 +206,7 @@
while($query->have_posts()): $query->the_post();
?>
<tr>
<td width="332" height="24"><a href="<?php the_permalink();?>" class="blue20"><?php the_title(); ?></a></td>
<td width="332" height="24"><a href="<?php the_permalink();?>" class="blue20"><?php echo mb_strimwidth(get_the_title(), 0, 33,"...","UTF-8"); ?></a></td>
</tr>
<tr>
<td style="padding:5px;"><font class="grey12-more"><?php echo get_the_excerpt();?><a href="<?php the_permalink() ?>" class="grey10bg">更多>></a></td>
Expand All @@ -231,7 +231,7 @@
$query = new WP_Query("posts_per_page=4&category_name=".$cat_name);
while($query->have_posts()): $query->the_post();
?>
<li class="li"><a href="<?php the_permalink(); ?>" class="black14"><?php the_title(); ?></a><font class="grey10"><?php the_time("m-d"); ?></font></li>
<li class="li"><a href="<?php the_permalink(); ?>" class="black14"><?php echo mb_strimwidth(get_the_title(), 0, 33,"...","UTF-8"); ?></a><font class="grey10"><?php the_time("m-d"); ?></font></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
<!-- 头题文字循环结束 -->
Expand All @@ -253,7 +253,7 @@
$query = new WP_Query("posts_per_page=6&category_name=".$cat_name);
while($query->have_posts()): $query->the_post();
?>
<li class="li"><a href="<?php the_permalink(); ?>" class="black14"><?php the_title(); ?></a><font class="grey10"><?php the_time("m-d"); ?></font></li>
<li class="li"><a href="<?php the_permalink(); ?>" class="black14"><?php echo mb_strimwidth(get_the_title(), 0, 33,"...","UTF-8"); ?></a><font class="grey10"><?php the_time("m-d"); ?></font></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
</tr>
Expand All @@ -278,7 +278,7 @@
$query = new WP_Query("posts_per_page=5&category_name=".$cat_name);
while($query->have_posts()): $query->the_post();
?>
<li class="li"><a href="<?php the_permalink(); ?>" class="black14"><?php the_title(); ?></a><font class="grey10"><?php the_time("m-d"); ?></font></li>
<li class="li"><a href="<?php the_permalink(); ?>" class="black14"><?php echo mb_strimwidth(get_the_title(), 0, 33,"...","UTF-8"); ?></a><font class="grey10"><?php the_time("m-d"); ?></font></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
</td>
Expand All @@ -289,7 +289,7 @@
$query = new WP_Query("posts_per_page=5&category_name=".$cat_name);
while($query->have_posts()): $query->the_post();
?>
<li class="li"><a href="<?php the_permalink(); ?>" class="black14"><?php the_title(); ?></a><font class="grey10" style="padding-right:9px; "><?php the_time("m-d"); ?></font></li>
<li class="li"><a href="<?php the_permalink(); ?>" class="black14"><?php echo mb_strimwidth(get_the_title(), 0, 33,"...","UTF-8"); ?></a><font class="grey10" style="padding-right:9px; "><?php the_time("m-d"); ?></font></li>
<?php endwhile; wp_reset_query(); ?>
</ul></td>
</tr>
Expand All @@ -312,7 +312,7 @@
$query = new WP_Query("posts_per_page=5&category_name=".$cat_name);
while($query->have_posts()): $query->the_post();
?>
<li class="li"><a href="<?php the_permalink(); ?>" class="black14"><?php the_title(); ?></a><font class="grey10"><?php the_time("m-d"); ?></font></li>
<li class="li"><a href="<?php the_permalink(); ?>" class="black14"><?php echo mb_strimwidth(get_the_title(), 0, 33,"...","UTF-8"); ?></a><font class="grey10"><?php the_time("m-d"); ?></font></li>
<?php endwhile; wp_reset_query(); ?>
</ul></td>
<td width="290" style="padding-left:10px; ">
Expand All @@ -323,7 +323,7 @@
$query = new WP_Query("posts_per_page=5&category_name=".$cat_name);
while($query->have_posts()): $query->the_post();
?>
<li class="li"><a href="<?php the_permalink(); ?>" class="black14"><?php the_title(); ?></a><font class="grey10" style="padding-right:9px; "><?php the_time("m-d"); ?></font></li>
<li class="li"><a href="<?php the_permalink(); ?>" class="black14"><?php echo mb_strimwidth(get_the_title(), 0, 33,"...","UTF-8"); ?></a><font class="grey10" style="padding-right:9px; "><?php the_time("m-d"); ?></font></li>
<?php endwhile; wp_reset_query(); ?>
</ul></td>
</tr>
Expand Down Expand Up @@ -368,7 +368,7 @@
$query = new WP_Query("posts_per_page=6&category_name=".$cat_name);
while($query->have_posts()): $query->the_post();
?>
<li class="li"><a href="<?php the_permalink(); ?>" class="black14"><?php the_title(); ?></a><font class="grey10"><?php the_time("m-d"); ?></font></li>
<li class="li"><a href="<?php the_permalink(); ?>" class="black14"><?php echo mb_strimwidth(get_the_title(), 0, 33,"...","UTF-8"); ?></a><font class="grey10"><?php the_time("m-d"); ?></font></li>

<?php endwhile; wp_reset_query(); ?>
</ul>
Expand Down

0 comments on commit 61f8f82

Please sign in to comment.