WordPress-Post-Like-System icon indicating copy to clipboard operation
WordPress-Post-Like-System copied to clipboard

just display likes....without hyperlink...non-clickable version

Open pknadella opened this issue 9 years ago • 1 comments

is it possible to just display the likes a post got.....something like a non-clickable version....not sure what to call it....may be it can be called a muted version

for example I will place the likes in the single post for users to click on it and register/unregister a like..... but on the home page(for instance a static home page to display latest/featured posts ) I just want to display the number of likes a post got, the user can not click the like icon to register a like, just display the likes.

pknadella avatar Jan 11 '16 15:01 pknadella

I wanted to do the same thing, I was able to get it to work with this: <?php echo get_post_meta( get_the_ID(), "_post_like_count", true ); ?>

^ That will output the number, which you can style / add icons to on your own.

Edit: The problem is that it doesn't output a number (even a 0) if the post has never been voted on, so you may have to add logic like: <?php $like_tally = get_post_meta( get_the_ID(), "_post_like_count", true ); $like_output = ($like_tally > 1)? $like_tally : "0"; ?>

And then call <?php echo $like_output; ?> where you want to output the number.

Edit: For some reason, the above outputs 0 even if the post has 1 like, only switching to show the real number if it has at least 2 likes. Looking into it, but I'm not an expert PHP'er, so I'll update again if I figure out how to get around that pickle.

Edit: Duh, just needed an equal sign:

<?php $like_tally = get_post_meta( get_the_ID(), "_post_like_count", true ); $like_output = ($like_tally >= 1)? $like_tally : "0"; ?>

ste7enm avatar Jan 15 '16 21:01 ste7enm