Tags list, an add-on to my tags mod
I just whipped this one up per a request from Brian over at The Miniblog (check it out, excellent design, shows what sNews can look like with the right talent). If you have installed my tags mod for sNews, then you can use this to retrieve a list of your tags, comma separated, and clickable (to pass the tag to the search engine).
This mod does not rank your tags by occurrences as a standard tag cloud would, though that's possible to do. So back up your snews.php file and let's get started.
First, we need to add the function, so copy & paste the following function just above the final php closing tag (the ?> at the very bottom) in snews.php;
If you're using my tags mod version 1 and want to continue using that, simply replace the highlighted text with ?search_query= instead of tag/
// this function grabs all the meta_keywords, removes duplicates and builds a comma separated list
function get_taglist($showpages="0") {
if ($showpages == "1") {
$pages_query = "category != '-1' ";
} else {
$pages_query = "category > 0 ";
}
$now = date("Y-m-d H:i:s",time());
$sql = "SELECT distinct(keywords_meta) FROM "._PRE."articles WHERE ".$pages_query." AND date <= '".$now."' AND published='1' AND visible = 'YES' AND keywords_meta != ''";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
$x = "1";
while ($row = mysql_fetch_array($result)) {
if ($x < $count) {
$suffix = ", ";
} else {
$suffix = "";
}
$tagslist .= $row['keywords_meta'].$suffix;
$x++;
}
$tagslist = explode(", ",$tagslist);
$tagslist = array_unique($tagslist);
sort($tagslist);
$keyCount = count($tagslist);
if ($keyCount > 0) {
echo '<div class="taglist">';
for ($i = 0; $i < $keyCount; $i++) {
if ($i == 0) {
$pre = "";
} else {
$pre = ", ";
}
if (!empty($tagslist[$i])) {
echo $pre.'<a href="'._SITE.'tag/'.urlencode($tagslist[$i]).'/" title="See more articles on '.$tagslist[$i].'">'.$tagslist[$i].'</a>';
}
}
echo "</div>";
}
}
Now, all you need to do is add the following function call to your index.php file where you want the list displayed, change the "0" to a "1" to show tags from sNews pages, or leave at "0" to display tags from only articles;
<?php get_taglist("0"); ?>
That should be it, if you want to change the styling, all the links are inside a div with the class of "taglist", so add that to your stylesheet and have fun. Below is an example of the results on my site... slightly different format as I'm using SEF links for my tags now, I'll be releasing that mod later on... peace.
Update #1: Jan 23rd, 2009 @ 8:35 pm - corrected div class style instructions, it's class is taglist, not tagslist. Also updated the query to not show the keywords if the article is published in the future.
Update #2: Jan 26th, 2009 @ 5:09 pm - added the sort() function to format the tags list alphabetically.
Update #3: Mar 3rd, 2009 @ 6:16 am - added trailing to tag links.


Comments
RSS Comments Feed
Fred K
Very nice mod though. Cheers!
Matt
hmmm, looks like you're correct about missing the trailing slash, however I don't think that would actually throw any error, except maybe a duplicate content message in Google Webmaster Tools, but that's another story.
You can fix that by adding the slash like below;
Fred, do you have one of my tags mod installed? If you haven't installed one of the tags mod, you'll need to do that first, as the tag list and tag cloud mods are add-ons and require the tags mod and it's tag search function.
http://mdj.us/snews-cms/hacks-mods/tags-mod-for-snews-version-2/
Fred K
I have it working locally now. Not sure where I'd gone wrong because I did have your tag mod version installed, but instead of trying to find the error I just rolled back to a previous version and reinstalled the tag mods. And it's working now so... No problems!
Thanks!
Matt
Yeah, "modding" isn't exactly simple for sNews, it's more like hack'n things up, lol, it can be easy to miss a step.
Therein also lies the beauty of sNews... I can bend it to my will :)
By the way, I enjoy your site, I stop by several times a week.
Fred K
Unfortunately something on my domain server screws this up. As I said before, it works locally with MAMP (PHP5/SQL5), but not on my domain server which also happens to be running PHP5 and SQL 5 (haven't checked the actual dot numbers to see if there's a difference there. It's really strange. The mod is good, my host is ... odd. :/
Fred K
(forgot to upload the lang file... meh-)
sorry
Matt
You actually just gave me the idea for my next little "mod". Notice how you have to enter your Name/Website/Email with every comment, this info should be sticky if you choose.
So I'm going to mod the comments to have a "remember me" check box so it'll set a cookie and remember your reader's name and website info if they like.
Hmmm, now I just have to find the free time!
Fred K
Oh and I like this comment preview thingy. Very swish, if there is such a word. lol
Matt
Anyways, back on topic... if you're getting a 404 header from sNews, it's likely because it's missing the hard-coded page. Can you verify the "tag" page is in the cat_listSEF?
$l['cat_listSEF'] = 'archive,contact,sitemap,tag,login,administration,admin_category,admin_article,article_new,extra_new,page_new,snews_categories,snews_articles,extra_contents,snews_pages,snews_settings,snews_files,logout,groupings,admin_groupings';The comment preview is just a small snippet of code if you use jQuery :)
http://mdj.us/web-development/ajax-javascript/live-comment-previewing-using-the-jquery-library/
Sven/Philippe
Oui. It's me: inspecteur Sven. The buggy man.
I got a curious issue with the taglist Mod.
The mod was working fine but I had to change my htaccess file recently and this tags page Mod didn't work anymore on the distant website. But locally it still works.
In my Tags page I call the function by php get_taglist("1");.
The breadcrumb says "you're on the tags page" but it shows the home page.
As I use the body id Mod I saw that the body id for the tags page was id="administration" and not id="tags".
I've checked if something was wrong in my code with this Mod. An nope.
Of course both "tags" and "tag" are in my $l['cat_listSEF'].
Any idea of the reason of this issue?
Thanks in advance Matt.
PS:I can't see the "highlighted code"???
Matt
Thanks, I've been cleaning up my stylesheet and some older "highlights" were a different style, I have fixed it now.
As for the strange error, that's very odd, what kind of header is the server sending? Are you getting a 200? What change did you make to .htaccess?
Sven/Philippe
See http://on-air.hiseo.fr/tags/...
I got a 200 OK.
Here is the online htaccess:
------
RewriteEngine On
RewriteBase /
RewriteRule ^(.+)\)$ $1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.+)$ $1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ index.php?category=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^html5/html5-ameliorer-referencement/\)$ http://on-air.hiseo.fr/html5/html5-ameliorer-referencement [R=301,L]
RewriteRule ^fatras/google-indexer-contenu/\)$ http://on-air.hiseo.fr/fatras/google-indexer-contenu/ [R=301,L]
RewriteRule ^sitemap.xml$ http://on-air.hiseo.fr/sitemap-carnet.xml.gz [R=301,L]
RewriteRule ^html5/html5-grands-comptes-gmf/\)$ http://on-air.hiseo.fr/html5/html5-grands-comptes-gmf/ [R=301,L]
---------------
locally I have this body id="administration" too but the page is printed. Weirdo... weirdo...
Sven/Philippe
look at this http://on-air.hiseo.fr/tag/WAI/
3 letters case?
Sven/Philippe
Did you change the link I gave above and add?
/.../
adding this makes the access OK.
About the WAI case: look at the answer given: there's no result for AI.
Where's is the "W" too???
I'm getting totally nuts.
Matt
the first I made, this one;
http://www.mdj.us/snews-cms/hacks-mods/adding-tags-to-snews-cms/
or the second, this one;
http://www.mdj.us/snews-cms/hacks-mods/tags-mod-for-snews-version-2/
Sven/Philippe
Matt
OK, so it looks like two problems in all, first the "tags" page displays the home page. Second, the tags seem to need to be lower case for REGEXP (shouldn't be the case, but whatever).
First, within the tagsearch function, add the bit below
$tags_query = trim($tags_query);
<span class="highlight">$tags_query = strtolower($tags_query); // add me</span>
Let me know if that fixes the individual tag view.
Matt
$tags_query = trim($tags_query);
<span class="highlight">$orig_query = $tags_query; // add me first!
$tags_query = strtolower($tags_query); // add me</span>
and then change the two instances where it displays the tags_query to disply the original (un-lower cased) query;
stripslashes(entity($tags_query))
to
stripslashes(entity(<span class="highlight">$orig_query</span>))
Sven/Philippe
$tags_query = ereg_replace("\W", " ", $tags_query);
Where does it comme from? I ignore.
Commenting it out made the W appears.
Seems that there is the TAGS page issue only.
Where does this string "/.../"" comes from?
Matt
Hmmm... just looked at your tags page again, seems to be working now?
Sven/Philippe
What! You can see it???
http://on-air.hiseo.fr/tags/
I can't!
Matt
There was a left floated image of some sort. The tags were wrapped around it...
Sven/Philippe
It's the poster of Dada.
You mean the days before this morning?
Matt
So odd.
Sven/Philippe
I'm sure you saw it.
I didn't.
Same files locally.
Not the same htaccess.
/tags/ works on my machine, but must go to /tags/.../ to see it on line. Incredible.
Why do both have this body id: body id="administration"
They should have body id="tags"?
Ah! Forget to tell, I'm using tagcloud version#2.
You know: the one with "see more tags".
Now I have that message :"Tags must be at least 2 characters!"