Viewing 15 replies - 16 through 30 (of 35 total)
  • Thread Starter John

    (@dpinc)

    Lastly if thumbnails and images it won’t show title?

    Plugin Author keesiemeijer

    (@keesiemeijer)

    Can you post all the code (for this plugin) you have in your functions.php file?

    Thread Starter John

    (@dpinc)

    MYID - CHANGE
    SHORTCODE - [related_posts_by_tax posts_per_page="4" format="images" taxonomies="post_tag"]
    
    Functions.php
    
    #######
    
    add_filter( 'the_content', 'add_related_posts_after_post_content' );
    function add_related_posts_after_post_content( $content ) {
    
        //check if it's a single post page.
        if ( is_single() ) {
    
            // check if we're inside the main loop
            if ( in_the_loop() && is_main_query() ) {
    
                // add your own attributes here (between the brackets [ ... ])
                $shortcode = '[related_posts_by_tax posts_per_page="4" format="images" taxonomies="post_tag"]';
    
                // add the shortcode after the content
                $content = $content . $shortcode;
            }
        }
    
        return $content;
    }
    
    // Adds the 'Post Images' format to the widget
    // after the plugin's defaults are set (priority 11).
    add_action( 'wp_loaded', 'rpbt_add_post_images_format_widget', 11 );
    
    function rpbt_add_post_images_format_widget() {
    
        if ( !class_exists( 'Related_Posts_By_Taxonomy_Defaults' ) ) {
            return;
        }
    
        $defaults = Related_Posts_By_Taxonomy_Defaults::get_instance();
    
        // Add the new format.
        $defaults->formats['images'] = __( 'Post Images' );
    }
    
    // Sets the format to thumbnails if the Post Images format is used.
    // Adds filters to remove the sql used to only find posts with post thumbnails.
    add_filter( 'related_posts_by_taxonomy_shortcode_atts', 'rpbt_post_images_format' );
    add_filter( 'related_posts_by_taxonomy_widget_args', 'rpbt_post_images_format' );
    
    function rpbt_post_images_format( $args ) {
    
        // Check if the new images format is used.
        if ( 'images' === $args['format'] ) {
    
            // Set format to thumbnails if Post Images format is used.
            $args['format'] = 'thumbnails';
    
            // Removes the sql to search for posts with post thumbnails only.
            add_filter( 'get_meta_sql', '__return_empty_string', 23 );
    
            // Removes the filter after related posts are retrieved.
            add_filter( 'related_posts_by_taxonomy', 'rpbt_remove_meta_sql_filter' );
    
            // Removes the filter if no related posts were found.
            add_action( 'related_posts_by_taxonomy_after_display', 'rpbt_remove_meta_sql_filter' );
        }
    
        return $args;
    }
    
    // Remove the filter
    function rpbt_remove_meta_sql_filter( $results ) {
        remove_filter( 'get_meta_sql', '__return_empty_string', 23 );
        return $results;
    }
    
    // Use a fallback image if a post has no post thumbnail.
    add_filter( 'related_posts_by_taxonomy_post_thumbnail_link', 'rpbt_related_post_fallback_image', 10, 4 );
    
    function rpbt_related_post_fallback_image( $image, $attr, $related, $args ) {
    
        if ( !empty( $image ) ) {
            // Post thumbnail found.
            return $image;
        }
    
        $image_args = array(
            'numberposts' => 1,
            'order' => 'ASC',
            'post_mime_type' => 'image',
            'post_parent' => $related->ID,
            'post_status' => null,
            'post_type' => 'attachment',
        );
    
        $attachments = get_children( $image_args );
    
        if ( !empty( $attachments ) ) {
            // Post attachment image found.
            $attachments = array_values( $attachments );
            $attachment_id = (int) $attachments[0]->ID;
    
            // Use the first attachment image.
            $image = wp_get_attachment_image( $attachment_id , $args['size'], false, $attr['describedby'] );
        } else {
            /**
             * Use your own fallback image here.
             *
             * Example of an image uploaded with the media editor.
             * Change the attachment ID (123) below to your uploaded fallback image ID.
             * And remove the two foreward slashes at the beginning.
             */
    
            $image = wp_get_attachment_image( MYID, $args['size'], false, $attr['describedby'] );
        }
    
        $image = $image ? "<a>{$image}</a>" : '';
    
        return $image;
    }
    Plugin Author keesiemeijer

    (@keesiemeijer)

    Your theme is probably hiding the title with css. Can you share a link to your site?

    Thread Starter John

    (@dpinc)

    I had change it to default – perhaps you can check what is going on – SKTSolution.Com

    Thread Starter John

    (@dpinc)

    images + thumbnails – just tooltip TITLE but not below image TITLE

    Plugin Author keesiemeijer

    (@keesiemeijer)

    On what page can I find the related posts?
    By title you mean the post title?

    [Edit] Aha, I understand.
    Please set the format back to images and let me take a look.

    Thread Starter John

    (@dpinc)

    Thread Starter John

    (@dpinc)

    HOLD one give me 5 mminutes

    Thread Starter John

    (@dpinc)

    Please check it now

    Plugin Author keesiemeijer

    (@keesiemeijer)

    Checking it

    Plugin Author keesiemeijer

    (@keesiemeijer)

    Your theme is hiding the caption.

    Try adding this to your child theme’s stylesheet:

    .related-gallery .gallery-caption {
    	position: relative;
    	opacity: 1;
    }

    Thread Starter John

    (@dpinc)

    Done but still the same

    Plugin Author keesiemeijer

    (@keesiemeijer)

    Close the header of your child theme’s stylesheet like so:

    /*
     Theme Name: Layers Child
     Description:
     Author:
     Template: layerswp
     Version:
     License:
     License URI:
    */

    Thread Starter John

    (@dpinc)

    ok noted done

Viewing 15 replies - 16 through 30 (of 35 total)
  • The topic ‘Links & Image’ is closed to new replies.