1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. This forum is for release discussion only. Discussions that do not relate specifically to the resource release should be discussed in another, more appropriate forum.
    Dismiss Notice
  3. This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

Tweet Per-Post

Discussion in 'Template Modifications [Archive]' started by Onimua, Apr 5, 2011.

  1. Onimua

    Onimua Well-Known Member

    This guide will let you put a Twitter button beside each post, allowing you to link to specific posts within a thread instead of the entire thread, or put a link to tweet beneath each post, whichever you prefer.

    Displaying Tweet Link Beside a Post

    Copy this code:
    HTML:
    <xen:if is="{$xenOptions.tweet.enabled}">
    <xen:if is="{$controllerName} == 'XenForo_ControllerPublic_Thread'">
        <div class="tweet shareControl">
            <a href="http://twitter.com/share" class="twitter-share-button"
                data-count="horizontal"
                data-lang="{xen:helper twitterLang, $visitorLanguage.language_code}"
                data-url="{xen:link canonical:posts, {$post}}"
                {xen:if {$thread.title}, 'data-text="{$thread.title}"'}
                {xen:if {$xenOptions.tweet.via}, 'data-via="{$xenOptions.tweet.via}"'}
                {xen:if {$xenOptions.tweet.related}, 'data-related="{$xenOptions.tweet.related}"'}>{xen:phrase tweet}</a>
        </div>
    </xen:if>
    </xen:if>
    Go to your message_user_info template and look for this at the bottom:

    HTML:
        <span class="arrow"><span></span></span>
    </div>
    CODE GOES HERE
    </div>
    Between the two </div> tags, past the code you copied before and save the template.

    The last thing is to go into EXTRA.css and paste the following code in there as well:

    HTML:
    .messageUserInfo .tweet { margin-top: 10px; }
    The end result looks like this:

    under_avatar.png

    Displaying Tweet Link Under a Post

    Alternatively, if you want to make a Tweet link to match the other links below the message, copy this code:

    HTML:
    <xen:if is="{$xenOptions.tweet.enabled}">
    <xen:if is="{$controllerName} == 'XenForo_ControllerPublic_Thread'"><a href="http://twitter.com/share?url={xen:link canonical:posts, {$post}}" target="_blank" class="item control tweet">{xen:phrase tweet}</a></xen:if>
    </xen:if>
    Then go to post template. Find this section:

    HTML:
    <div class="publicControls">
                    <a href="{xen:link threads/post-permalink, $thread, 'post={$post}'}" class="item muted postNumber hashPermalink" title="{xen:phrase permalink}">#{xen:calc '{$post.position} + 1'}</a>
                    <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>
                    <xen:if is="{$canReply}">
                        <a href="{xen:link threads/reply, $thread, 'quote={$post.post_id}'}" data-postUrl="{xen:link posts/quote, $post}" class="ReplyQuote item control reply" title="{xen:phrase reply_quoting_this_message}"><span></span>{xen:phrase reply}</a>
                    </xen:if>
    
                    CODE HERE
                </div>
    Right before the closing </div>, paste the code you just copied.

    The end result looks like this:

    tweet_link.png

    You can put the link wherever you want in the section of course, just look at the surrounding HTML and place it where you want. :)

    Thanks to King Kovifor for pointing something out and OperaManiac for the lead on being able to make the link-only option.
     
    1BJK903, Vilandra, zaiger and 9 others like this.
  2. Peggy

    Peggy Well-Known Member

    Thank you SO much Onimua for fulfilling my request for this add-on.

    I'm going to add it to my site right now and test it out.
     
  3. Peggy

    Peggy Well-Known Member

    OK, easy as all get-out to install, excellent!

    The only issue is, after installation, there is a 1 in the box on all posts, lol.
     
  4. Onimua

    Onimua Well-Known Member

    Ah, seems there might be a complication with the thread itself that I didn't think about. Let me see if there's something I can do... :unsure:
     
  5. Peggy

    Peggy Well-Known Member

    ah I see what you're saying. If the thread's been tweeted, then there's going to be a 1 by each of the posts.
    I can understand the logic behind that actually.

    However when I tweeted the one post, the other posts did stay at 1 while the post I tweeted went to 2.
    I don't know about anyone else, but I'm ok with that.
     
  6. Jeremy

    Jeremy XenForo Moderator Staff Member

    Very nice Onimua. :) Sent you a PC. :p
     
  7. Onimua

    Onimua Well-Known Member

    Go back and use the new code I put (it's really a one-line change) and tell me how that works.
     
    Peggy and Jeremy like this.
  8. Peggy

    Peggy Well-Known Member

    It worked, and it's AWESOME!!!

    Thanks so much for taking the time out of your blog coding to do this add-on.
    Fantastic!

    And thanks KK for whatever assistance you gave Onimua. :p
     
  9. Onimua

    Onimua Well-Known Member

    Unfortunately I can't take all the credit. KK pointed out the one bug that was there. :rolleyes: lol
     
    Renada and Jeremy like this.
  10. Peggy

    Peggy Well-Known Member

    I thanked him too. Now off you go back to your blog.

    I just love XenForo and its group of helpful members, coders, etc!
     
  11. Jeremy

    Jeremy XenForo Moderator Staff Member

    Well, I take credit for 1/6 of the code. :D I'm just in a very playful mood today with Onimua. :D
     
    Shelley likes this.
  12. Tigratrus

    Tigratrus Well-Known Member

    Gratz to both of you... :)
     
  13. Peggy

    Peggy Well-Known Member

    I am a happy camper. :)
     
  14. ArnyVee

    ArnyVee Well-Known Member

    This is great....definitely adding this :)
     
    Peggy likes this.
  15. Renada

    Renada Active Member

    Hi Onimua,

    Thank you for this, it works really well :) I've one small problem, I just noticed that this adds the tweet option to private conversations too which could be a bit dodgy in the hands of a trouble-maker.

    Is there a way to prevent this bit?

    Regards,
    Renada :)
     
  16. Peggy

    Peggy Well-Known Member

    Oohh I hadn't noticed this. Yes that could lead to trouble.
     
  17. Onimua

    Onimua Well-Known Member

    :confused:

    Yes, there is a way... give me a bit of time.
     
    Peggy likes this.
  18. Peggy

    Peggy Well-Known Member

    Take your time, darlin.
     
  19. Onimua

    Onimua Well-Known Member

    I've updated the first post with updated code.
     
    Peggy and laztrix like this.
  20. Renada

    Renada Active Member

    Onimua, replacing that new code with the old code seems to have removed the tweet option from everywhere - did I do something wrong?

    Regards,
    Renada :)
     

Share This Page