| View previous topic :: View next topic |
| Author |
Message |
bobby Site Admin


Joined: Jan 20, 2009 Posts: 600 Location: North Carolina
    votes: 4
|
Posted: Sat Nov 20, 2010 9:57 am Post subject: How to add Disqus to news |
|
|
This is how to add the Disqus commenting system to the Tricked Out News 2.5. You should also be able to do the same with the standard news module although the code to replace will be different.
The first thing to do is head over to http://disqus.com/ and create an account. Once you create your Disqus account, you can customise it in their dashboard. You will need to copy their Install Universal Code to a good editor such as Notepad++. Their code will have 2 parts, the Embed code and the Comment count. Keep the two codes separate.
You will need to edit their code a little bit. First in the Embed Code find:
Code:
/**
* var disqus_identifier; [Optional but recommended: Define a unique identifier (e.g. post id or slug) for this thread]
*/
|
and replace it with:
Code:var disqus_identifier = "'.$sid.'";
|
so that the new code looks like this:
Code:<script type="text/javascript">
var disqus_identifier = "'.$sid.'";
(function() {
|
Next, you will need to replace the single quotes with double quotes like so:
'script' becomes "script"
'text/javascript' becomes "text/javascript"
etc...
There are 5 sets of quotes that need to be changed in the Embed code and 5 in the Comment Count code.
Save these codes and get ready to start editing your site.
In your News/articles.php, find the following code starting at around line 345:
Code:if (empty($mode) OR $mode != 'nocomments' OR $acomm == 0 OR $articlecomm == 1) {
|
From there all the way to the end will be replaced with the new code. So you will start there and remove ALL the code to the end of the file and replace it with this:
Code://Start Disqus
if ($anonpost==1 OR (isset($admin) AND (is_admin($admin) AND $acomm == 0)) OR (is_user($user) AND $acomm == 0)) {
global $db, $prefix, $cookie;
cookiedecode($user);
if (count($cookie)<2) $uname='';
else $uname = $cookie[1];
global $db, $prefix;
$sql = 'SELECT user_email FROM '.$user_prefix.'_users WHERE username = \''.$uname.'\'';
$result = $db->sql_query($sql);
$row = $db->sql_fetchrow($result);
$user_email = $row['user_email'];
if (is_user($user)) {
echo'
<script type="text/javascript">
var disqus_skip_auth = true;
var disqus_def_name = "'.$uname.'";
var disqus_def_email = "'.$user_email.'";
</script>';
}
echo'Paste Disqus Embed code Here';
echo'Paste Disqus Comment Count code Here';
}
// End Disqus
include_once ('footer.php');
?>
|
Of course, you will need to paste your edited Embed code and Comment code where it says to Paste your code in this mod.
That should do it. Be sure to back up your site before starting. _________________ Tricked Out News |
|
| Back to top |
|
 |
Palbin Regular


Joined: May 23, 2009 Posts: 15
  
|
|
| Back to top |
|
 |
bobby Site Admin


Joined: Jan 20, 2009 Posts: 600 Location: North Carolina
    votes: 4
|
|
| Back to top |
|
 |
RamonTF Regular


Joined: Mar 17, 2009 Posts: 11
   
|
|
| Back to top |
|
 |
bobby Site Admin


Joined: Jan 20, 2009 Posts: 600 Location: North Carolina
    votes: 4
|
Posted: Sat Nov 20, 2010 4:26 pm Post subject: |
|
|
When disqus supplied me with the universal code, it was already in there.
In disqus, in the top right, click switch to old disqus.
click on comments and then click install instructions from the drop down at your discus name. Those instructions should have the info already there. i don't know why the new disqus does not have that filled in for you. _________________ Tricked Out News |
|
| Back to top |
|
 |
bobby Site Admin


Joined: Jan 20, 2009 Posts: 600 Location: North Carolina
    votes: 4
|
|
| Back to top |
|
 |
RamonTF Regular


Joined: Mar 17, 2009 Posts: 11
   
|
|
| Back to top |
|
 |
bobby Site Admin


Joined: Jan 20, 2009 Posts: 600 Location: North Carolina
    votes: 4
|
Posted: Sun Nov 21, 2010 12:40 am Post subject: |
|
|
To add the comment count to the index:
In the modules/News/index.php, find:
Code:
$story_link = '<a href="news.html?amp;file=article&sid=' . $sid . '">';
|
after that add:
Code:
$hometext = $hometext.'<br /><br /><script type="text/javascript">
var disqus_shortname = "Your Shortname";
var disqus_identifier = "'.$sid.'";
(function () {
var s = document.createElement("script"); s.async = true;
s.type = "text/javascript";
s.src = "http://disqus.com/forums/" + disqus_shortname + "/count.js";
(document.getElementsByTagName("HEAD")[0] || document.getElementsByTagName("BODY")[0]).appendChild(s);
}());
</script><img src="images/news/comment.png" alt="Comments" /><a style="font-size:13px; font-weight:bold;" href="modules.php?name=N ews&file=article&sid=' . $sid . '#disqus_thread"></a>';
|
You will need to change Your Shortname to the shortname Disqus gave you. You will also need to remove the space in the bottom link in the word N ews. Shortlinks rewrites it on my site if i do not leave the space in it. I added some simple styling to the link, you can change it to your liking. _________________ Tricked Out News
Last edited by bobby on Sun Nov 21, 2010 9:52 am; edited 2 times in total |
|
| Back to top |
|
 |
RamonTF Regular


Joined: Mar 17, 2009 Posts: 11
   
|
Posted: Sun Nov 21, 2010 8:39 am Post subject: |
|
|
Yeah! this work like a charm!
... but I've modified some code for this work fine for me
The correct code for me is:
Code:$hometext = $hometext.'<br><br><script>
var disqus_shortname = "myshortname";
var disqus_identifier = "'.$sid.'";
(function () {
var s = document.createElement("script"); s.async = true;
s.type = "text/javascript";
s.src = "http://disqus.com/forums/" + disqus_shortname + "/count.js";
(document.getElementsByTagName("HEAD")[0] || document.getElementsByTagName("BODY")[0]).appendChild(s);
}());
</script><div align="right"><img src="images/news/comment.png" alt="Comments" align="absmiddle"> <a href="news.html?amp;file=article&sid=' . $sid . '#disqus_thread"></a></div>';
|
With the other code the link on the counter lead me to an error page (I think, shortlinks issue). Also note the point (.) afther the "$hometext = $hometext .[..]"
I think this is a great addition to the news, good work. _________________ "Who controls the past controls the future. Who controls the present controls the past."--George Orwell |
|
| Back to top |
|
 |
RamonTF Regular


Joined: Mar 17, 2009 Posts: 11
   
|
|
| Back to top |
|
 |
bestbuildpc I might as well work here


Joined: Nov 16, 2009 Posts: 61
  
|
|
| Back to top |
|
 |
bobby Site Admin


Joined: Jan 20, 2009 Posts: 600 Location: North Carolina
    votes: 4
|
|
| Back to top |
|
 |
sortilege2021 Regular


Joined: Nov 25, 2010 Posts: 16
     
|
|
| Back to top |
|
 |
bobby Site Admin


Joined: Jan 20, 2009 Posts: 600 Location: North Carolina
    votes: 4
|
|
| Back to top |
|
 |
sortilege2021 Regular


Joined: Nov 25, 2010 Posts: 16
     
|
|
| Back to top |
|
 |
|
|