1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.4 Moving Likes to Control Bar

Discussion in 'Styling and Customization Questions' started by Amaury, Jan 12, 2015.

  1. Amaury

    Amaury Well-Known Member

    I'd like to add a "View Likes" link in the controls bar to the right of Like / Unlike (it's shown differently below, but yeah) that will bring up the like listings overlay (rather than having to wait for four or more people to like the content); in addition, if there are no likes, the link will not display.

    How can I accomplish this? I've already managed to hide the likes bar with CSS.

    Here's a mockup:

    Likes Mockup.png

    Thanks!
     
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    HTML:
    <a href="{xen:link 'posts/likes', $post}" class="item control OverlayTrigger">View Likes</a>
    
     
    Amaury likes this.
  3. Amaury

    Amaury Well-Known Member

    Which template would I edit?
     
  4. Optic

    Optic Well-Known Member

    @Maru: the area you want to edit should be in the post template.

    You probably want to add your new link just after:
    Code:
    <xen:if is="{$post.canLike}">
    <a href="{xen:link posts/like, $post}" class="LikeLink item control {xen:if $post.like_date, unlike, like}" data-container="#likes-post-{$post.post_id}"><span></span><span class="LikeLabel">{xen:if $post.like_date, {xen:phrase unlike}, {xen:phrase like}}</span></a>
    </xen:if>
     
    Amaury likes this.
  5. Amaury

    Amaury Well-Known Member

    Got it. However, I've run into an issue and a conditional issue:
    • It is not showing on my own posts.
    • How do I make so it only shows if the post has likes?
     
  6. Jeremy

    Jeremy XenForo Moderator Staff Member

    You can't like your own post, so obviously it will not show on your own posts if you include that conditional.
     
  7. Amaury

    Amaury Well-Known Member

    Sorry, let me clarify. The conditional would make it so the "View Likes" link only appears on posts that have been liked. My issue right now is that it's appearing on posts that don't have any likes as well. In addition, the "View Likes" link is not viewable on my own posts, and even on a default style, you can still see how many people have liked your posts.
     
  8. mike406

    mike406 Member

    This is what we needed.
    Code:
    <xen:if is="{$post.likes}">
            <a href="{xen:link 'posts/likes', $post}" class="item control OverlayTrigger">{xen:phrase khflare_view_likes}</a>
    </xen:if>
    
     
    Amaury likes this.
  9. Amaury

    Amaury Well-Known Member

    And in regard to the first part, I completely misunderstood what @Optic said. I placed the code @Jeremy gave underneath the Like/Unlike link within the conditional there, which is why it wasn't showing for people's own posts.

    Thank you all for the help.
     
  10. Amaury

    Amaury Well-Known Member

    So @Nights brought up a good point on our site:

    How can I accomplish this? Would I add some variable to the phrase to make it appear as View Likes: X?

    Also, when you like or unlike a post, the likes bar automatically appears or disappears. Is there any way to get the View Likes link we added to automatically appear or disappear after liking or unliking a post with out having to refresh the page?
     
  11. Amaury

    Amaury Well-Known Member

    In regard to the first question above, I tried adding {count} to the phrase to no avail. I'm assuming I have to edit the phrase I have in the template as well and add something?
     
  12. Amaury

    Amaury Well-Known Member

    I think I got it:

    Code:
    <a href="{xen:link 'posts/likes', $post}" class="item control OverlayTrigger">{xen:phrase khflare_view_likes, 'count={xen:number $post.likes}'}</a>
     

Share This Page