Skip to content
Public Ticket #18023

how to post a like counter to all posts

Conversation thread

Adrian Schaub replied

Customer Reply

Perfect - you are my god / godess :-)

The only comment for later readers of this string is to not forget to remove <php endif;?> after the section below (because the "if" for the zero dropped away).

thanks again and have a great day!

Best regards, Adrian

PenciDesign Supporter replied

Staff Reply

Hi,

If you want to show 0 like, please modify the code:

<?php
$like = penci_getPostCountLike(get_the_ID());
?>
<span class="otherl-like">
      <?php printf( _n( '%s like', '%s likes', $like, 'soledad' ), number_format_i18n( $like ) );?>
</span>

Regards,
PenciDesign.


Adrian Schaub replied

Customer Reply

Excellent - thanks for the quick turnaround! It works perfectly, IF there is a like. However there is no "0 likes" for the pictures that have no likes yet (see screenshot attached, where the left pic has a like and right no like). Not a big issue but to my recollection different from the comments, where it shows "0 comments" as well. Is there an easy fix?

Thanks again for your much appreciated help, Best regards, Adrian

PenciDesign Supporter replied

Staff Reply

Hi,

Please go to Appearance → Theme Editor:

- Select theme to edit: Soledad,

- Navigate to the content-masonry.php file,

- Find:

<?php if( penci_isshow_reading_time( $hide_readtime ) ): ?>
    <span class="otherl-readtime"><?php penci_reading_time(); ?></span>
<?php endif; ?>

- Add this code:

<?php
$like = penci_getPostCountLike(get_the_ID());
if ( $like ):?>
<span class="otherl-like">
      <?php printf( _n( '%s like', '%s likes', $like, 'soledad' ), number_format_i18n( $like ) );?>
</span>
<?php endif;?>

image.png

Regards,
PenciDesign.

Adrian Schaub started the conversation

Conversation Start

Hello I would like to post a like counter to all posts on the homepage (see screenshot). The question is similar to https://pencidesign.ticksy.com//ticket/2822354/ but I would like to post number of likes instead f number of comments. Thanks and best regards, Adrian

Want to join this conversation or access attachments? Sign in first.