Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author keesiemeijer

    (@keesiemeijer)

    Hi, Li-An

    Have you seen this
    https://keesiemeijer.wordpress.com/related-posts-by-taxonomy/recipes/#image-fallback

    With some adjustments we can change it to suit your needs.

    Do you have any s2member code (you use in your theme templates) to see if the current user is a member?

    Thread Starter Li-An

    (@li-an)

    Thanks for the link – I did not see it.

    Yes, S2Member provides plenty of code to check is the user is member or not

    <?php if (current_user_can("access_s2member_level1")) { ?>
    Some content
    <?php } ?>

    or

    <?php if (current_user_cannot("access_s2member_level1")) { ?>
    Other content
    <?php } ?>

    I will read carefully the code you provide for image fallback.

    Plugin Author keesiemeijer

    (@keesiemeijer)

    Use the ‘thumbnails’ format and add a filter to the gallery images. Try it with this in your (child) theme’s functions.php file.

    // Use a fallback image for non members.
    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
    
    		if ( !current_user_can( "access_s2member_level1" ) ) {
    
    			// Dont use post thumbnail for a non member
    			//
    			// Show specific fallback image
    			// change attachment id 123 below
    
    			$image = wp_get_attachment_image( 123, $args['size'], false, $attr['describedby'] );
    			$image = "<a href='{$attr['permalink']}' title='{$attr['title']}'>{$image}</a>";
    		}
    	}
    
    	return $image;
    }

    Now members without the capability “access_s2member_level1” get to see your fallback image.

    btw:
    consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost. Or create a plugin with the code above.

    Thread Starter Li-An

    (@li-an)

    Thanks a lot. No problem for the child theme – I already work on a child theme. But you are right for the plugin. If I want the function to work with different themes, a plugin may be very useful.

    Thanks again for your quickness !

    Thread Starter Li-An

    (@li-an)

    It works ! It works !

    Plugin Author keesiemeijer

    (@keesiemeijer)

    I’m glad to hear ??

    Thread Starter Li-An

    (@li-an)

    Well, it does not work exactly as I hoped because I was not precise enough.

    I want to show the fallback thumbnail for a particular category. As I understand, your code won’t be able to check the category of the related post ?

    I tried

    if ( current_user_cannot( "access_s2member_level1" )&&in_category(255) ) {

    but it shows only fallback image.

    Plugin Author keesiemeijer

    (@keesiemeijer)

    Try adding the post ID.

    if ( current_user_cannot( "access_s2member_level1" ) && in_category( 255, $related->ID ) ) {

    Thread Starter Li-An

    (@li-an)

    You made it. I learn eveyday about coding and WP functions. Thanks again.

    Plugin Author keesiemeijer

    (@keesiemeijer)

    You’re welcome ??

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘thumbnail for member’ is closed to new replies.