Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Michael Nelson

    (@mnelson4)

    There is!
    In YARPP settings, under “Display options for your website”, find the setting “Default display if no results:” and clear out the text. Then nothing will display when there are no related posts ??

    See https://drive.google.com/file/d/1kZ_LYuF82g7uyVR2A4zST-oh5z-Q9nqm/view

    Let us know how it goes!

    Thread Starter arskrigitsioniets

    (@arskrigitsioniets)

    The problem is that there is another function above, “Heading”, and I use it. I would like that there will be heading if there are related posts and there will be no heading if there are no related posts.

    Plugin Support Michael Nelson

    (@mnelson4)

    Aha, ok. For thumbnails, for now you would need to use a custom template, which is a little technical, but here’s the steps:

    Click to copy the templates, choose the thumbnails custom template, then modify wp-content/themes/{yourtheme}/yarpp-template-thumbnail.php to be the following:

    
    <?php
    /*
     * Copy of YARPP's built-in thumbnails template, except the heading is only shown if any related posts are found.
     */
    
    if ( !$this->diagnostic_using_thumbnails() )
    	$this->set_option( 'manually_using_thumbnails', true );
    
    $options = array( 'thumbnails_heading', 'thumbnails_default', 'no_results' );
    extract( $this->parse_args( $args, $options ) );
    
    // a little easter egg: if the default image URL is left blank,
    // default to the theme's header image. (hopefully it has one)
    if ( empty($thumbnails_default) )
    	$thumbnails_default = get_header_image();
    
    $dimensions = $this->thumbnail_dimensions();
    
    if (have_posts()) {
    	$output .= '<h3>' . $thumbnails_heading . '</h3>' . "\n";
    	$output .= '<div class="yarpp-thumbnails-horizontal">' . "\n";
    	while (have_posts()) {
    		the_post();
    
    		$output .= "<a class='yarpp-thumbnail' rel='norewrite' href='" . get_permalink() . "' title='" . the_title_attribute('echo=0') . "'>" . "\n";
    
    		$post_thumbnail_html = '';
    		if ( has_post_thumbnail() ) {
    			if ( $this->diagnostic_generate_thumbnails() )
    				$this->ensure_resized_post_thumbnail( get_the_ID(), $dimensions );
    			$post_thumbnail_html = get_the_post_thumbnail(null, $dimensions['size'], array('data-pin-nopin' => 'true') );
    		}
    
    		if ( trim($post_thumbnail_html) != '' )
    			$output .= $post_thumbnail_html;
    		else
    			$output .= '<span class="yarpp-thumbnail-default"><img src="' . esc_url($thumbnails_default) . '" alt="Default Thumbnail" data-pin-nopin="true" /></span>';
    
    		$output .= '<span class="yarpp-thumbnail-title">' . get_the_title() . '</span>';
    		$output .= '</a>' . "\n";
    
    	}
    	$output .= "</div>\n";
    } else {
    	$output .= $no_results;
    }
    
    $this->enqueue_thumbnails( $dimensions );
    
    

    That makes the thumbnail template exactly like the default thumbnails template, except it only shows the heading if there are any related posts.

    • This reply was modified 4 years, 6 months ago by Michael Nelson. Reason: explain template's purpose
    Thread Starter arskrigitsioniets

    (@arskrigitsioniets)

    It works, thanks! It would be convenient if you add such an option as a selectable item in settings in future updates.

    Plugin Support Michael Nelson

    (@mnelson4)

    Great! That’s a good idea, thanks. I agree that would be better than this entire code snippet, which not everyone is comfortable using.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘To hide heading if there no related post’ is closed to new replies.