• Resolved Rahul Ramesh

    (@rahulascents)


    When I try to display 6 related posts using Jetpack module, the layout gets pretty messed up.
    Here is the screenshot: https://worldanimeclub.com/wp-content/uploads/2014/06/jetpack.png

    And this is the code I use to display 6 related posts (code is added in functions.php)

    /*6 related posts*/
    function jetpackme_more_related_posts( $options ) {
        $options['size'] = 6;
        return $options;
    }
    add_filter( 'jetpack_relatedposts_filter_options', 'jetpackme_more_related_posts' );

    When I revert back to 3, layout becomes normal and working again. But my client needs at least 6 related post items. Hope someone can help me ??

    https://www.ads-software.com/plugins/jetpack/

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    Related Posts seem to be properly displayed on my end:
    https://i.wpne.ws/W7zM

    If you still experience issues, could you try in a different browser, and let me know if your problem is browser-specific?

    Thanks!

    Thread Starter Rahul Ramesh

    (@rahulascents)

    Hi Jeremy,
    I repaired it yesterday. The problem was that, in Jetpack Related Posts module, while showing more than 3 related articles, if the post title is long then it will end up being displayed like this: https://worldanimeclub.com/wp-content/uploads/2014/06/jetpack.png

    I corrected it by using the code below, such that if a post title length is more than 27 characters then the remaining characters of the title will be stripped down. This will preserve the layout of the related posts for 6 or more items.

    protected function _get_title( $post_title, $post_content ) {
    		if ( ! empty( $post_title ) ){
                        $post_title = substr($post_title, 0, 27);
                        $post_title = $post_title.'.....';
    			return $post_title;
                            }

    Hi Rahul,

    Could you please tell me exactly where you placed your fix as I am getting the same problem.

    I tried placing it in the function.php but it crashed my site, if you could let me know the exact place that would be great.

    Thanks

    Thread Starter Rahul Ramesh

    (@rahulascents)

    Hi, you should find the code

    /**
    	 * Returns either the title or a small excerpt to use as title for post.
    	 *
    	 * @param string $post_title
    	 * @param string $post_content
    	 * @uses strip_shortcodes, wp_trim_words, __
    	 * @return string
    	 */

    in wp-content/plugins/jetpack/modules/related-posts/jetpack-related-posts.php
    then you should replace all the code under it with

    protected function _get_title( $post_title, $post_content ) {
    		if ( ! empty( $post_title ) ){
                        $post_title = substr($post_title, 0, 27);
                        $post_title = $post_title.'.....';
    			return $post_title;
                            }
    
    		return __( 'Untitled Post', 'jetpack' );
    	}

    leave the remaininf code, starting from

    /**
    	 * Returns a plain text post excerpt for title attribute of links.............

    untouched

    Thread Starter Rahul Ramesh

    (@rahulascents)

    Sorry, that was a little confusing, it will be better explained like this
    Original Code:

    protected function _get_title( $post_title, $post_content ) {
    		if ( ! empty( $post_title ) )
    			return $post_title;
    
    		$post_title = wp_trim_words( strip_shortcodes( $post_content ), 5 );
    		if ( ! empty( $post_title ) )
    			return $post_title;
    
    		return __( 'Untitled Post', 'jetpack' );
    	}

    Replaced Code:

    protected function _get_title( $post_title, $post_content ) {
    		if ( ! empty( $post_title ) ){
                        $post_title = substr($post_title, 0, 27);
                        $post_title = $post_title.'.....';
    			return $post_title;
                            }
    
    		$post_title = wp_trim_words( $post_title, 3, '...' );
    		if ( ! empty( $post_title ) )
    			return $post_title;
    
    		return __( 'Untitled Post', 'jetpack' );
    	}

    Thanks Rahul,

    The code worked perfectly. I noticed however the the title is also trimmed from the tooltip when you hover over the thumbnails.

    Have you found a way to fix this?

    I also found a plugin called shareaholic that looked similar to the Jetpack related posts I may give that a try.

    @j33 let us know if we can answer any questions reg. Shareaholic.

    Thread Starter Rahul Ramesh

    (@rahulascents)

    @j33, well I use Jetpack for most my needs because I can stay close to original WordPress as much as possible and Jetpack related posts will reduce server load since it is handled by WordPress.com servers.

    Ya, Shareaholic is also good. But do not bother much about Related Posts, their main purpose is to reduce bounce rates, so just make sure you display at least 6 related articles under a post.

    Thanks for all your help Rahul.

    Hey shareaholic, I haven’t tried out your plugin yet but will do so soon and if it works out better than the Jetpack related posts I will be happy to keep it on my site.

    This is my site if you are interested: Travel on Inspiration

    @j33 You should give it a shot. You may be pleasantly surprised ?? btw, your site looks great!

    Case studies: https://blog.shareaholic.com/the-definitive-guide-to-related-content-ebook/ * More info: https://shareaholic.com/publishers/recommendations/

    @rahul Shareaholic also does all the computations on its servers – keeping your server load to a minimal.

    I don’t want to hijack this thread. If you guys have additional questions, please feel free to email me directly! jay at shareaholic dot com

    Hi there, @rahul, having same problem with mobile devices here.

    Your code works ?? but ??

    1. I am getting back tooo many dots after the title text
    https://prntscr.com/4hkzbx.
    2. In case of really long titles, the code makes the title vanish and become ‘Null’ https://prntscr.com/4hkzpo

    Any idea?

    Thanks!

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic ??

    That’s indeed something we need to look at in Jetpack. I created an issue in our bug tracker, and you can follow our progress here:
    https://github.com/Automattic/jetpack/issues/1091

    Thanks Jeremy, I will follow your sure successfull progress.

    Jesus

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Problem with Related Posts’ is closed to new replies.