Replacing the function $title_length with a more accurate truncating function

Posted in: Newspaper
Post count: 101

Hi,

I’m currently trying to modify td_module_8.php

When loading the posts it states:
<?php echo $this->get_title($title_length);?>

and a little above that

    function render() {
        ob_start();
        $title_length = $this->get_shortcode_att('m8_tl');
        ?>

Well now, we would like to truncate based upon number of characters, and then on whole words.
Searching the internet I find this bit of code, meaning it will allow a max of 35 characters :

echo substr( $title, 0, strrpos( substr( $title, 0, 35), ' ' ) );

and this one too
function truncateStr($input, $length)
{
//only truncate if input is actually longer than $length
if(strlen($input) > $length)
{
//check if there are any spaces at all and if the last one is within the given length if so truncate at space else truncate at length.
if(strrchr($input, ” “) && strrchr($input, ” “) < $length)
{
return substr( $input, 0, strrpos( substr( $input, 0, $length), ' ' ) )."…";
}
else
{
return substr( $input, 0, $length )."…";
}
}
else
{
return $input;
}
}

How would I be able to replace this bit of code with something like the one mentioned above ?
Every effort I have made so far has resulted in the posts simply not showing at all…

kind regards

Nick

extra info.
The goal is too truncate titles which are too long, preferrably replacing the missing words with “…”, in an effort
to not create extra paragraphs and distort the design of the site.

Post count: 20688

Hi,

So you want to control the length of the title. You could use the general excerpt settings for each module type
https://forum.tagdiv.com/excerpts-introduction/
Or the newly added excerpt options by individual block, in the tagDiv composer
https://www.screencast.com/t/vnxurDXwiVf
The “…” will be added automatically for both title and post excerpt.

Thanks

Post count: 101

Normally yes, but I’ve made custom loops etc that cause the tagdiv composer to not work…

So, I take it creating a new page using tagdiv might be an option.
Is it possible to show posts from a certain category, with a certain taxonomy ?

The point is that we are trying to make the posts appear from category musicreviews, which have the taxonomy alphabetical letter A on one page.

And later on posts from category livereviews, which are also in the taxonomy alphabetical letter A on a different page…

Post count: 20688

The theme blocks can display custom post types, but these cannot be filtered by taxonomies.
The filtering of blocks works only with categories (you can choose which category/categories are included or excluded) so there would be no way of controlling taxonomies.

Viewing 4 posts - 1 through 4 (of 4 total)
The forum ‘Newspaper’ is closed to new topics and replies.