sNews 1.7 (current stable version) > General questions

Adding a Tweet Me (Twitter) button to all articles?

(1/2) > >>

Tominator:
OK I've looked through the past threads about doing this but I don't think it applies any more now that Twitter is supporting it's own retweet function. For example, here's the javascript for a tweet me button for my account.


--- Code: ---<a href="https://twitter.com/share" class="twitter-share-button" data-via="GeldnerGroup">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
--- End code ---

How do I incorporate this into my sNews site so it doesn't have to be manually entered into each article? (I'd prefer it NOT appear on Pages or Extra Contents.) I'm basically using a real simple index.php file that just calls the center() function for all the content.

Thanks!

mosh:
A simple way is to add this code in your index.php
where ever you want the link to show, It will show only when article view.

--- Code: ---<?php
if($_POS == 1){
echo '<a href="https://twitter.com/share" class="twitter-share-button" data-via="GeldnerGroup">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>';
}
?>

--- End code ---

Tominator:
Well it shows the Tweet Button correctly but it doesn't pick up the URL for the article when you click it. It opens Twitter correctly and puts the article title in place but the URL isn't there. Plus the button ends up AFTER the Comments block when I throw it into index.php as follows:

--- Code: ---<div id="content">
<br />
<div class="entry">
<?php center(); ?>
<?php
if($_POS == 1){
echo '<a href="https://twitter.com/share" class="twitter-share-button" data-via="GeldnerGroup">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>';
}
?>

</div>
</div>

--- End code ---

mosh:
You can place the code in function articles, under paginator call.

if (!empty($currentPage) && ($num> $article_limit) && $on) {
   paginator( $currentPage, $totalPages, l('paginator'));
}

if($_POS == 1){
echo '<a href="https://twitter.com/share" class="twitter-share-button" data-via="GeldnerGroup">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>';
}


I can't help you with the tweeter code, don't know nothing about it.

blankspace:
Hello Tominator! I try this with Matt Jones tweet button, on http://www.mdj.us/snews-cms/hacks-mods/add-a-retweet-button-to-your-snews-cms-articles-and-pages/, and it works. The code I try is this:


--- Code: ---} else {
$shorten = 9999000;
if($_POS == 1) {
if (strpos($text,'<!-- NOBADGE -->') === false) {
    $tweet = '<a href="https://twitter.com/share" class="twitter-share-button" data-via="GeldnerGroup">Tweet</a>
    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>';
    $text = $tweet.$text;
    }
}
}

--- End code ---

To understand use of "<!-- NOBADGE -->", must read Matt's instructions.
Note: I only try on local server but it works for me.

Ciao,
/Pax

Navigation

[0] Message Index

[#] Next page

Go to full version