Need Help! Limit length title

Status
Not open for further replies.

ntn0408

Active Member
58
2014
12
80
Hello,
I using Arras theme, i want to limit length title of posts (the title below thumbnails) on homepage.
Everyone can help me.
Thank you
 
3 comments
Open your index.php or whatever area you want to limit your character.
Then replace
PHP:
the_title
with this code.
PHP:
<a href="<?php the_permalink() ?>">
<?php
$thetitle = $post->post_title;
$getlength = strlen($thetitle);
$thelength = 25;
echo substr($thetitle, 0, $thelength);
if ($getlength > $thelength) echo "...";
?>
</a>
 
Open your index.php or whatever area you want to limit your character.
Then replace
PHP:
the_title
with this code.
PHP:
<a rel="nofollow" href="<?php the_permalink() ?>">
<?php
$thetitle = $post->post_title;
$getlength = strlen($thetitle);
$thelength = 25;
echo substr($thetitle, 0, $thelength);
if ($getlength > $thelength) echo "...";
?>
</a>
I found the code:
PHP:
$postheader .= '<h3 class="entry-title"><a href="' . get_permalink() . '" rel="bookmark">' . get_the_title() . '</a></h3>';
I think red code above for title. But i dont know do that to shorten my title.
Please help me.
Thank you.
 
Code:
[COLOR=#0000BB][FONT=monospace][I]$thetitle [/I][/FONT][/COLOR][COLOR=#007700][FONT=monospace][I]= [/I][/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]get_the_title[/FONT][/COLOR][COLOR=#007700][FONT=monospace]()[/FONT][/COLOR][COLOR=#007700][FONT=monospace][I];
[/I][/FONT][/COLOR][COLOR=#0000BB][FONT=monospace][I]$getlength [/I][/FONT][/COLOR][COLOR=#007700][FONT=monospace][I]= [/I][/FONT][/COLOR][COLOR=#0000BB][FONT=monospace][I]strlen[/I][/FONT][/COLOR][COLOR=#007700][FONT=monospace][I]([/I][/FONT][/COLOR][COLOR=#0000BB][FONT=monospace][I]$thetitle[/I][/FONT][/COLOR][COLOR=#007700][FONT=monospace][I]);
[/I][/FONT][/COLOR][COLOR=#0000BB][FONT=monospace][I]$thelength [/I][/FONT][/COLOR][COLOR=#007700][FONT=monospace][I]= [/I][/FONT][/COLOR][COLOR=#0000BB][FONT=monospace][I]25[/I][/FONT][/COLOR][COLOR=#007700][FONT=monospace][I];
$shortentitle = [/I][/FONT][/COLOR][COLOR=#0000BB][FONT=monospace][I]substr[/I][/FONT][/COLOR][COLOR=#007700][FONT=monospace][I]([/I][/FONT][/COLOR][COLOR=#0000BB][FONT=monospace][I]$thetitle[/I][/FONT][/COLOR][COLOR=#007700][FONT=monospace][I], [/I][/FONT][/COLOR][COLOR=#0000BB][FONT=monospace][I]0[/I][/FONT][/COLOR][COLOR=#007700][FONT=monospace][I], [/I][/FONT][/COLOR][COLOR=#0000BB][FONT=monospace][I]$thelength[/I][/FONT][/COLOR][COLOR=#007700][FONT=monospace][I]);
if ([/I][/FONT][/COLOR][COLOR=#0000BB][FONT=monospace][I]$getlength [/I][/FONT][/COLOR][COLOR=#007700][FONT=monospace][I]> [/I][/FONT][/COLOR][COLOR=#0000BB][FONT=monospace][I]$thelength[/I][/FONT][/COLOR][COLOR=#007700][FONT=monospace][I])
[/I][/FONT][/COLOR][COLOR=#007700][FONT=monospace][I]$[/I][/FONT][/COLOR][COLOR=#007700][FONT=monospace][I]shortentitle [/I][/FONT][/COLOR][COLOR=#007700][FONT=monospace][I].= "...."[/I][/FONT][/COLOR][COLOR=#007700][FONT=monospace][I];
[/I][/FONT][/COLOR]
[COLOR=#0000BB][FONT=monospace]$postheader [/FONT][/COLOR][COLOR=#007700][FONT=monospace].= [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'<h3 class="entry-title"><a href="' [/FONT][/COLOR][COLOR=#007700][FONT=monospace]. [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]get_permalink[/FONT][/COLOR][COLOR=#007700][FONT=monospace]() . [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'" rel="bookmark">'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]. $[/FONT][/COLOR][COLOR=#007700][FONT=monospace][I]shortentitle[/I][/FONT][/COLOR][COLOR=#007700][FONT=monospace] .[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]'</a></h3>'[/FONT][/COLOR][COLOR=#007700][FONT=monospace]; [/FONT][/COLOR]
 
Status
Not open for further replies.
Back
Top