user roles – Recent posts on homepage: different thumbnail based on logged in status and post category

Question

This works well on archive.php but not working on the homepage. For some reason the first statement doesn’t get applied: if a post is in Members category and user is not logged in, it’s supposed to show a default placeholder image, but instead it’s still showing the actual post thumbnail.

<?php if (!is_user_logged_in() && in_category('members')) { ?>
    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
        <img src="<?php bloginfo('template_directory'); ?>/img/default-login.jpg" alt="<?php the_title(); ?>" />
    </a>
                                
<?php } 
    else if (is_user_logged_in() || !in_category('members')) { ?>                 

        <a href="<?php echo get_permalink($post_item['ID']) ?>">
            <?php echo get_the_post_thumbnail($post_item['ID'], 'news-thumb'); ?>
        </a>
                                    
    <?php } else { ?>
            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                <img src="<?php bloginfo('template_directory'); ?>/img/default.jpg" alt="<?php the_title(); ?>" />
            </a>

    <?php } ?>

0
Phantasmix 1 month 2021-05-10T19:34:22-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse