News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

How can I insert Tweetmeme button on FIRST post in every topic?

Started by swiftmed, April 23, 2010, 01:18:58 PM

Previous topic - Next topic

swiftmed

Hey Guys,

I am inserting a tweetmeme button at the start of every post. I have got it implemented OK, but it really DOES appear on every post. I only want it to show up on the first post of every topic. Here is the code Im using:
<hr width="100%" size="1" class="hrcolor" />if ($context[\'first_message\']==$message[\'id\']) echo\'
<script type="text/javascript">
tweetmeme_source = \'swiftmed\';
</script>
<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script>\';

<div class="post"', $message['can_modify'] ? ' id="msg_' . $message['id'] . '"' : '', '>', $message['body'], '</div>', $message['can_modify'] ? '
<img src="' . $settings['images_url'] . '/icons/modify_inline.gif" alt="" align="right" id="modify_button_' . $message['id'] . '" style="cursor: pointer; display: none;" onclick="modify_msg(\'' . $message['id'] . '\', \'' . $context['session_id'] . '\')" />' : '' , '
</td>
</tr>';



But the output is messed up. It's showing like this at the moment:



Can anybody tell me what Im doing wrong, or give me the correct code so this works please? Using SMF 2.0 RC3.
With Regards,
Andrew MacDonald

http://cherylanncole.co.uk/forums
SMF 2.0 RC2

swiftmed

With Regards,
Andrew MacDonald

http://cherylanncole.co.uk/forums
SMF 2.0 RC2

flapjack

well, I would do it adding it directly to index.template.php, have you considered that?

swiftmed

Quote from: flapjack on April 23, 2010, 08:36:04 PM
well, I would do it adding it directly to index.template.php, have you considered that?

Thats a really good idea. I didn't think of that. Thank you!!
With Regards,
Andrew MacDonald

http://cherylanncole.co.uk/forums
SMF 2.0 RC2

sAce

Quote from: flapjack on April 23, 2010, 08:36:04 PM
well, I would do it adding it directly to index.template.php, have you considered that?

How would you do that ? the posts/topics are handled by display.template.php

swiftmed

Quote from: S-Ace on April 24, 2010, 09:47:52 AM
Quote from: flapjack on April 23, 2010, 08:36:04 PM
well, I would do it adding it directly to index.template.php, have you considered that?

How would you do that ? the posts/topics are handled by display.template.php

The tweetmeme button will appear on every single page of the site wont it. Not ideal, but if there is really no way to have them only appear on the first post in a topic, it's my only alternative. It's not the way id like to do it ideally.

Surely there must be a way to ONLY insert the button on the first post in a topic folks???
With Regards,
Andrew MacDonald

http://cherylanncole.co.uk/forums
SMF 2.0 RC2

sAce

use this
<div class="inner" id="msg_', $message['id'], '"', '>';
if ($message['counter'] == 0)

echo '<div id="twme" style="float:right; padding:5px;">
<script type="text/javascript">
tweetmeme_source = \'swiftmed\';
</script>
<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div>';

echo ' ', $message['body'], '</div>
</div>';



swiftmed

Quote from: S-Ace on April 24, 2010, 10:43:45 AM
use this
<div class="inner" id="msg_', $message['id'], '"', '>';
if ($message['counter'] == 0)

echo '<div id="twme" style="float:right; padding 5px;">
<script type="text/javascript">
tweetmeme_source = \'swiftmed\';
</script>
<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div>';

echo ' ', $message['body'], '</div>
</div>';


That did the job. Thank you so much!!!! I knew it must have been possible, im just not technical enough to know how to do it, so thanks for your advice!!
With Regards,
Andrew MacDonald

http://cherylanncole.co.uk/forums
SMF 2.0 RC2

SN


sAce


swiftmed

Quote from: SN on April 24, 2010, 12:36:27 PM
this is a cool edit should be a mod

I agree. It should be either included as a mod, or something that comes with SMF out of the box. I have also added Facebook Like buttons to the forum as well.
With Regards,
Andrew MacDonald

http://cherylanncole.co.uk/forums
SMF 2.0 RC2

sAce


swiftmed

Quote from: S-Ace on April 24, 2010, 12:58:19 PM
FB Like mod is in approval queue i think

Only prob with Facebook like is you can only suggest the URL of your website in its code. Because SMF doesn't have permalinks, you cant use "<?php the_permalink(); ?>" in the FB Like code like you could if you were adding it to wordpress. So you can't like individual threads on your forum.

Why exactly SMF doesn't have the ability to have something like <?php the_permalink(); ?> like Wordpress does to make it easy for such things is beyond me. Ah well. :(
With Regards,
Andrew MacDonald

http://cherylanncole.co.uk/forums
SMF 2.0 RC2

Arantor

Because as I told you, SMF URLs are dynamic because the content can be altered by it.

That said, you could have it link to just the topic as a whole (which is $scripturl . '?topic=' . $topic . '.0') like the canonical URLs.

swiftmed

Quote from: Arantor on April 24, 2010, 05:53:13 PM
Because as I told you, SMF URLs are dynamic because the content can be altered by it.

That said, you could have it link to just the topic as a whole (which is $scripturl . '?topic=' . $topic . '.0') like the canonical URLs.

Ah I see. So what is the exact piece of code I would use to link to that canonical URLS thingy you just said about. Where I would normally enter <?php the_permalink(); ?> for wordpress, what exactly would I replace that with?
With Regards,
Andrew MacDonald

http://cherylanncole.co.uk/forums
SMF 2.0 RC2

Arantor

I actually gave you the code to add, in fact, however I acknowledge that scope can be an issue so let me simplify it down.

Add this to the end of Subs.php.

function the_permalink()
{
global $scripturl, $topic, $modSettings;

if (empty($topic))
return $scripturl;

return ($scripturl . (!empty($modSettings['queryless_urls']) ? '/topic,' . $topic . '.0.html' : '?topic=' . $topic . '.0'));
}

swiftmed

Thanks for that. I have done as you said.

Tweetmeme buttom seems to be working fine now. Thanks Arantor!
With Regards,
Andrew MacDonald

http://cherylanncole.co.uk/forums
SMF 2.0 RC2

diontoradan

can i use custom url for this tweetmeme? i like to have my own domain as the shorturl. tweetmeme only supports shortlist of short url provider.

Arantor

I think you've answered your own question - if Tweetmeme doesn't support it, you can't do it with Tweetmeme, in which case you're almost talking about starting a new service that isn't Tweetmeme.

wedost.com

How to do this in smf 1.1.11?

Quote from: S-Ace on April 24, 2010, 10:43:45 AM
use this
<div class="inner" id="msg_', $message['id'], '"', '>';
if ($message['counter'] == 0)

echo '<div id="twme" style="float:right; padding:5px;">
<script type="text/javascript">
tweetmeme_source = \'swiftmed\';
</script>
<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script></div>';

echo ' ', $message['body'], '</div>
</div>';


CapadY

Please, don't PM me for support unless invited.
If you don't understand this, you will be blacklisted.

Advertisement: