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.

[func]get_taglist:|:0[/func]

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.

Share this post:
Share of Facebook Tweet this post Share this post on Google+ Email this post


Comments

RSS Comments Feed


Sven/Philippe's Avatar

Sven/Philippe

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?

Matt's Avatar

Matt

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?

Sven/Philippe's Avatar

Sven/Philippe

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.

Matt's Avatar

Matt

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.

Sven/Philippe's Avatar

Sven/Philippe

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.

Matt's Avatar

Matt

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;

[func]get_taglist:|:0[/func]

Sven/Philippe's Avatar

Sven/Philippe

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.



(optional, not publicly displayed) (optional)

Site News

About Matt

Privacy Policy | About Me
Copyright © 2002 - 2012 Matt Jones
HTML5/CSS3
Back to Top Back to top