WordPress.org

Ready to get started?Download WordPress

Forums

Yet Another Related Posts Plugin (YARPP)
[resolved] [Plugin: Yet Another Related Posts Plugin] Limiting display of characters per title (5 posts)

  1. mauriciomesquita
    Member
    Posted 3 years ago #

    I want to limit the title of the posts related to 40 characters.

    As in example:

    Original title:
    "The view of my title is limited to a certain number of characters"

    View:
    "The view of my title is limited to a certain..."

    How? I thank you all for help. I am a Brazilian fan of mitcho

    http://wordpress.org/extend/plugins/yet-another-related-posts-plugin/

  2. chadrew
    Member
    Posted 3 years ago #

    I would use YARPP custom templates and put the code limiting the title length there. So, first make sure that in YARPP options you're set to use custom templates. For example, "yarpp-template-example.php". Then open that file in your theme editor and find this part:

    <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><!-- (<?php the_score(); ?>)--></li>

    Replace with:

    <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php echo substr(get_the_title(), 0, 40); ?>...</a><!-- (<?php the_score(); ?>)--></li>

    I'm no expert but this should work...

  3. mitcho (Michael Yoshitaka Erlewine)
    Member
    Plugin Author

    Posted 3 years ago #

    Thanks @chadrew! Indeed, I think that would work!

  4. mauriciomesquita
    Member
    Posted 3 years ago #

    Thanks!

    To limit to 40 characters and do not display words in half:

    <li><a href="<?php the_permalink() ?>" rel="bookmark">
    <?php
    $title_cortado = explode(" ", substr(get_the_title(), 0, 40));
    if(count($title_cortado) > 1) array_pop($title_cortado);
    $title_cortado = implode(" ", $title_cortado)."...";
    echo $title_cortado;
    ?>  </a><!-- (<?php the_score(); ?>)--></li>

    Thank you for your attention!
    Congratulations

  5. mitcho (Michael Yoshitaka Erlewine)
    Member
    Plugin Author

    Posted 3 years ago #

    Ah, nice as well.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic