• Resolved tuhinbiswas98

    (@tuhinbiswas98)


    i want to know ther any way to Limit Characters of related post Title ? i want to show 9 related post but its not looking good some of my post title long and some post title short that why i want to Limit Characters in related post Title but not in my home page only in related post

Viewing 15 replies - 1 through 15 (of 21 total)
  • Hi tuhinbiswas98. There are several ways to do this as discussed in this article. However, the easiest solution is to just chnage one line in the related-posts file.
    1. Copy /inc/related-posts.php from the parent theme to the same folder in your child theme.
    2. Find the following code near the bottom of the file:

    <h4 class="post-title">
    	<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    </h4><!--/.post-title-->

    3. Chnage this at the end of the line (the last instance, not “title=”):

    <?php the_title(); ?>

    to this:

    <?php echo wp_trim_words( the_title(), 5 ); ?>

    Change the number of words from 5 to whatever you like.

    Thread Starter tuhinbiswas98

    (@tuhinbiswas98)

    i try this but its not worrking ??

    Can you post a link to your site? Thanks.

    Thread Starter tuhinbiswas98

    (@tuhinbiswas98)

    yes https://pom111.tk/ i useing this site to try this code :O

    Thread Starter tuhinbiswas98

    (@tuhinbiswas98)

    What happens if you change this:

    <?php echo wp_trim_words( the_title(), 5 ); ?>

    to this:

    <?php echo wp_trim_words( get_the_title(), 5 ); ?>
    Thread Starter tuhinbiswas98

    (@tuhinbiswas98)

    i try <?php echo wp_trim_words( get_the_title(), 5 ); ?> but stil same noithing change ??

    And the file you are changing is located in wp-content/themes/your-child-theme/inc/related-posts.php?

    Thread Starter tuhinbiswas98

    (@tuhinbiswas98)

    yes that file in my child theme

    OK. To make sure the theme is using the correct file, I’d like you to add some text to the file in your child theme, just before the title <h4>, like this:

    this is a test <h4 class="post-title">
    	<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php get_the_title(); ?></a>
    </h4><!--/.post-title-->

    Let me know when you’ve done that and I’ll look at your test site again.

    Thread Starter tuhinbiswas98

    (@tuhinbiswas98)

    you want me to add that in my related-posts.php?

    before <h4 class=”post-title”>?

    Thread Starter tuhinbiswas98

    (@tuhinbiswas98)

    this is my full code of related-posts.php new one without any change ok

    <?php $related = alx_related_posts(); ?>
    
    <?php if ( $related->have_posts() ): ?>
    
    <h4 class="heading">
    	<i class="fa fa-hand-o-right"></i><?php _e('You may also like...','hueman'); ?>
    </h4>
    
    <ul class="related-posts group">
    
    	<?php while ( $related->have_posts() ) : $related->the_post(); ?>
    	<li class="related post-hover">
    		<article <?php post_class(); ?>>
    
    			<div class="post-thumbnail">
    				<a>" title="<?php the_title(); ?>">
    					<?php if ( has_post_thumbnail() ): ?>
    						<?php the_post_thumbnail('thumb-medium'); ?>
    					<?php elseif ( ot_get_option('placeholder') != 'off' ): ?>
    						<img src="<?php echo get_template_directory_uri(); ?>/img/thumb-medium.png" alt="<?php the_title(); ?>" />
    					<?php endif; ?>
    					<?php if ( has_post_format('video') && !is_sticky() ) echo'<span class="thumb-icon small"><i class="fa fa-play"></i></span>'; ?>
    					<?php if ( has_post_format('audio') && !is_sticky() ) echo'<span class="thumb-icon small"><i class="fa fa-volume-up"></i></span>'; ?>
    					<?php if ( is_sticky() ) echo'<span class="thumb-icon small"><i class="fa fa-star"></i></span>'; ?>
    				</a>
    				<?php if ( comments_open() && ( ot_get_option( 'comment-count' ) != 'off' ) ): ?>
    					<a>"><span><i class="fa fa-comments-o"></i><?php comments_number( '0', '1', '%' ); ?></span></a>
    				<?php endif; ?>
    			</div><!--/.post-thumbnail-->
    
    			<div class="related-inner">
    
    				<h4 class="post-title">
    					<a>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    				</h4><!--/.post-title-->
    
    				<div class="post-meta group">
    					<p class="post-date"><?php the_time('j M, Y'); ?></p>
    				</div><!--/.post-meta-->
    
    			</div><!--/.related-inner-->
    
    		</article>
    	<!--/.related-->
    	<?php endwhile; ?>
    	<?php wp_reset_postdata(); ?>
    
    <!--/.post-related-->
    <?php endif; ?>
    
    <?php wp_reset_query(); ?>

    you want me to add that in my related-posts.php?

    before <h4 class=”post-title”>?

    Yes, to the related-posts.php file in your child theme.

    Thread Starter tuhinbiswas98

    (@tuhinbiswas98)

    ok i did ad that code but nothing change look plz https://pom111.tk/

    Then the theme isn’t using the file that you updated. You’re sure it’s wp-content/themes/your-child-theme/inc/related-posts.php?

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘Limit Characters in related post Title’ is closed to new replies.