<?php
$args = array(
'wpp_start' => '<ul class="list-group list-group-flush post-number">',
'wpp_end' => '</ul>',
'post_type' => 'post',
'limit' => 5,
'range' => 'all',
'post_html' => '<li class="list-group-item"><a class="h6 h6-md h6-lg" href="{url}">{text_title}</a></li>',
'title_length' => 20
);
wpp_get_mostpopular($args );
?>
]]>This post is an example of what I’m referring to.
]]>For example, with very long titles such as ”2010 LAMBORGHINI GALLARDO LP550-2 VB”
I do not want it to say User @ ”2010 LAMBORGHINI GALLARDO LP550-2 VB” because that is too long and it creates two lines for one entry and with a total of 4 entries it moves the copyright under it everytime and it could get annoying for users.
I would just want to be able to set a limit for it at a maximum of certain amount of words or characters, can this be done ?
]]>Thanks.
]]>I’m using a dynamic sidebar with several widgets and I would like to trim the title/links display length once they reach a certain number of characters. I’ve found a function that’ll probably do what I need but I’ve got no idea how to apply it properly.
/**
* Add this to your page:
* <?php
* include “shorten_a_text_string.php”;
* echo ShortenText($text);
* ?>
* where $text is the text you want to shorten.
*
* Example
* Test it using this in a PHP page:
* <?php
* include “shortentext.php”;
* $text = “The rain in Spain falls mainly on the plain.”;
* echo ShortenText($text);
* ?>
*/
<?php
function ShortenText($text)
{
// Change to the number of characters you want to display
$chars = 25;
$text = $text." ";
$text = substr($text,0,$chars);
$text = substr($text,0,strrpos($text,' '));
$text = $text."...";
return $text;
}
?>
Hope you understand what I mean. Any help would be awesome, thanks.
]]>I have a limited amount of space, so I need to know how to restrict the output of the_title() to a certain number of characters (or words, preferably), and then insert a “…” to indicate that the title is shortened, but only if the title is shortened. Can anyone help?
]]>I have a section in my WP 2.7 blog with Recent Posts, but due to design i only want to show the first 50 chars of the_title(); of the posts.
Is that possible ?
Thanks in advance!
post_title LIKE ‘$letter%’
I don’t want to use plugin or custom select so can we just put at in the normal loop?
]]><?php
function shorten_text($text, $length) {
$shortened_text = substr($text, 0, $length);
$shortened_text .= '…';
return $shortened_text;
}
$title = 'Your very long title blah blah blah';
$shortened_title = shorten_text($title, 15);
print $shortened_title;
?>
Thanks
]]>