Tags list, an add-on to my tags mod
filed under: sNews CMS / Hacks & Mods
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.
32 comments
Add a new comment »Categories
Recent Entries
Recent Comments
- Dede (I checked it today in a shop. GT2 had some troubles with six ...)
- Matt (Bintang, You need to re-direct the url, try ...)
- jesth (Ohh.. why didn't I think of that, thanks alot.)
- Matt (Dede, I don't have Gran Turismo 2, any of the 2nd+ generation ...)
- Matt (Jesth, Just change the if condition, instead of looking for ...)
- jesth (Hi (again) Was wondering, is it possible to make it ...)
- Bintang Sembilan (Matt, thanks for your modd. I have apply it to my ...)
- Dede (Hello there. Can you check something for me? I want to buy ...)
- Matt (I think it's a driver issue Terrence, or it was a driver issue. ...)
Popular Entries
- Light-weight related articles mod for sNews 1.7 (4.5/5)
- Image / math hybrid captcha version 2, vastly improved (4.42/5)
- 1024x600 netbook wallpapers of Evangeline Lilly (4.4/5)
- Compact archives for sNews 1.7 (4.4/5)
- sNews Ajax Polls mod now available (4.38/5)
- Pretty date and comments bars in sNews CMS (4.35/5)
- Page caching mod for sNews 1.7 (4.33/5)
- Gravatar mod for sNews 1.7 (4.29/5)
- An improved tag cloud for sNews 1.7 (4.29/5)
Mar 3rd, 2009 at 3:45 am
Hey Matt, liking this one a lot but I think I'm doing something wrong. I have the tag list implemented on inkpattern.com (if you feel inclined to take a look) but the tag links don't work as expected -- certainly not like they do here. Clicking on any tag just brings you back to the start page. I noticed just now that my tags don't have a trailing slash but yours do ... that might be it. If you have any suggestions, I'm all ears. Meanwhile I'll do some bugchecking to see what I've done wrong.
Very nice mod though. Cheers!
Mar 3rd, 2009 at 6:12 am
Hi Fred,
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;
echo $pre.'<a href="'._SITE.'tag/'. urlencode($tagslist[$i]).'/" title="See more articles on '.$tagslist[$i].'">'.$tagslist[$i].'</a>';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/
Mar 3rd, 2009 at 5:48 pm
Hi Matt,
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!
Mar 3rd, 2009 at 5:59 pm
Great, that was easy! :)
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.
Mar 3rd, 2009 at 6:22 pm
I wish life was easy...
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. :/
Mar 3rd, 2009 at 6:27 pm
bah- figured it out. too stupid for words...
(forgot to upload the lang file... meh-)
sorry
Mar 3rd, 2009 at 6:43 pm
LOL Fred, I do that kinda crap all the time.
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!
Mar 5th, 2009 at 7:25 am
The weirdest part is that it (the tag cloud thing) works as it should on my local server --MAMP-- but not on my remote server where any tag link will throw a 404. I *think* it has to do with how my domain host uses the .htaccess but I'm not sure. it's a virtual server setup (servage.net) and they do warn about using specific .htaccess files can upset the server. Seems that's what's happening for me. Shame, the mod works really nicely otherwise.
Oh and I like this comment preview thingy. Very swish, if there is such a word. lol
Mar 5th, 2009 at 7:49 am
Fred, that's odd, if the rest of your site uses mod_rewrite just fine. I checked out the cloud on your site, one thing you'll find is because we're using MySQL full-text, the minimum character limit on the keywords is 4, kind a of pain I know, especially for common acronyms like CSS, IE, etc.
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/
Mar 11th, 2010 at 4:37 am
Uh oh... him again!
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"???
Mar 11th, 2010 at 6:51 am
Hi Sven,
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?
Mar 11th, 2010 at 7:05 am
Hi Matt. The bug is online.
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...
Mar 11th, 2010 at 7:35 am
Uh oh...
look at this http://on-air.hiseo.fr/tag/WAI/
3 letters case?
Mar 11th, 2010 at 7:48 am
Sorry... me again.
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.
Mar 11th, 2010 at 7:48 am
hmmm, something is likely gone wrong with the tag search function. Which version are you using?
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/
Mar 11th, 2010 at 7:52 am
The 2nd one with the 1st option.
Mar 11th, 2010 at 8:05 am
Hmmm, I think you mean the second option, because it works for you when the case is lowered, and the first option uses full-text, which has 4 character minimum by default.
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); $tags_query = strtolower($tags_query); // add meLet me know if that fixes the individual tag view.
Mar 11th, 2010 at 8:22 am
If that works, but shows the tag in lower case, then we'll want to reference the original tag query, so do something like this;
$tags_query = trim($tags_query); $orig_query = $tags_query; // add me first! $tags_query = strtolower($tags_query); // add meand then change the two instances where it displays the tags_query to disply the original (un-lower cased) query;
to
stripslashes(entity($orig_query))Mar 11th, 2010 at 8:25 am
Gee! Found out that line in the function:
$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?
Mar 11th, 2010 at 8:37 am
Hmmm, that line should replace non-word characters with blank space, but the ereg functions are deprecated and shouldn't be used anyways. We probably stuck that in there as a test or something?
Hmmm... just looked at your tags page again, seems to be working now?
Mar 11th, 2010 at 8:47 am
???
What! You can see it???
http://on-air.hiseo.fr/tags/
I can't!
Mar 11th, 2010 at 8:50 am
lol, strange, I did see it before (not now again).
There was a left floated image of some sort. The tags were wrapped around it...
Mar 11th, 2010 at 9:11 am
Yeap Matt that's it.
It's the poster of Dada.
You mean the days before this morning?
Mar 11th, 2010 at 9:16 am
No, when you were "fixing" the tag pages, I looked at the /tags/ page and saw it.
So odd.
Mar 11th, 2010 at 9:48 am
Lucky guy.;-)
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!"
Mar 11th, 2010 at 10:09 am
Okey okey...
In function center() there are those lines:
else {
global $categorySEF, $subcatSEF, $articleSEF;
# Fonction Search avec SEF URL
// begin new code
$url = explode('/',clean(cleanXSS($_GET['category'])));
if ($url[0] == "search") {
$search_query = $url[1];
}
if ($url[0] == "tag") {
$tags_query = $url[1];
}
if ($url[0] == "tags") {
$show_tags = $url[1];
}
// end tag Mod
Is the issue coming from here?
Mar 11th, 2010 at 11:54 am
Hmmm, no, that stuff in the center function shouldn't affect that...
I do see that if you add another trailing slash, it works...
http://on-air.hiseo.fr/tags//
Is that something with the .htaccess file perhaps?
Mar 12th, 2010 at 6:23 am
Hum... Matt... you maybe right sine it works locally, but...
any page created in snews should have its own ID isn'it?
The ID I use for Tags page should be added to the body tag. Am I wrong?.
Well it's not body id="tags" which is printed but body id="administration". That's pretty curious.
However it doesn't explain why a double slash in needed to get the page out when on the online website.
Mar 12th, 2010 at 7:44 am
Not necessarily. Did you create a "page" via the admin, or use a hard-coded "tags" SEF link in the $l['cat_listSEF'] variable?
I don't use the body id mod, but if you're using a hard-coded system page, then it's like the sitemap/contact/archive pages and you would need to make sure that mod understands that.
Mar 12th, 2010 at 8:56 am
Hello Matt,
thanks again for replying.
The TAGS page has been created via the admin panel AND use ['cat_listSEF'] (tags and tag are there).
What's is caussing the issue of the body id"administration" is in this part of the code:
unset( $catList[0], $catList[1], $catList[2], $catList[3] );
if ( $categorySEF || ( _ADMIN && $_GET['action'] ) ) {
if (
in_array( $_GET['action'], $catList ) ||
in_array( $categorySEF, $catList )
) {
$bodyID = 'administration';
} else $bodyID = $categorySEF;
For the moment I can't figure out where's the conflict with you mod.
Mar 12th, 2010 at 11:00 am
Sven, you shouldn't do both, it creates a conflict. Try removing the "tags" page from the cat_listSEF, and just having the tags page, and call the function like this in the page;
Mar 12th, 2010 at 11:29 am
That was it!!!
I'll send you an email tomorrow as I'm a bit in hurry by now.
Thanks a lot.
I'll bring you a coffee together with my email.