How can I create a latest tags box that sorts the latest and filters duplicates? I've been trying it with views but it's not working.

Comments

vm’s picture

Thinking about this a bit.... Taxononmy aren't nodes. Therefore I'm not sure the required information will be present where it concerns when the terms were created. Thus filtering latest may be a bit difficult unless they are turned into nodes. the category.module does this I think. It's been awhile since I've used it though and wasn't crazy about the implementation.

sp09’s picture

me too I'm not to big on it but I know it's very popular with content sites I want to fill up more space on my front page. I'll check out the category mod to see if it can get the job done, I'm not to big on working with php

vm’s picture

I'd test the snippet below before I went after the category module.

matt blaine’s picture

I had to do this recently and could not come up with a way in views to do this. I did do it as a block with PHP (you must have php available as a filter). It was in a hurry and should be tested somewhat but works for what I needed at the time.

<?
$sql = "SELECT term_data.name,term_data.tid FROM term_data LEFT JOIN term_node ON term_node.tid = term_data.tid LEFT JOIN node on node.nid = term_node.nid WHERE node.status = 1 AND node.moderate = 0 GROUP BY term_data.name ORDER BY node.created DESC LIMIT 0,10";
$query = db_query($sql);
$recent_out = '<div class="recenttags"><h4>Recent Tags:</h4>';
$recent_out .= '<ul class="recent">';
$recent_count = 0;
while ($recent = db_fetch_object($query)) {
  $recent_count++;
  $recent_out .= '<li>' . l($recent->name, 'taxonomy/term/' . $recent->tid) . '</li>';

}
$recent_out .= '</ul>';
$recent_out .= '</div>';
if ($recent_count>0){
print $recent_out;
}
?>

change the 10 depending on how many you want displayed. The group by will get rid of duplicates

sp09’s picture

where do I place this code?

vm’s picture

I did do it as a block with PHP (you must have php available as a filter).

in a new block administer -> blocks -> add block
with the php input format provided by the core phpfilter.module

Though personally, I would test it in a page content type with the php input format to ensure that it works first. Bad php in a block can break the site at which point you would have to manually manipulate the database to turn the offending block off.

sp09’s picture

how do I create a php format in format input?

vm’s picture

you don't. you switch to it.

enable the phpfilter.module in administer -> modules
when creating a block, click on the "input formats" link under the body text area.
choose php format as you would with any other input format.

matt blaine’s picture

blocks add a block place it in the block body. Set the input format to PHP code. Then from the block overview page place it where you want it to appear

sp09’s picture

Ok I've got it set up and it's working perfect. I added more tag results (25) and I took away the Recent Tags title but gave the same title as the block title for a better look. No duplicates no problems, thanks a lot matt I appreciate it and to you too vmu.

matt blaine’s picture

Testing that sql on another site seems to not quite be right. Some just use tags not in the list and some not used in a while where in the list.

Now using this and testing so far seems correct

$sql = "SELECT 
distinct term_data.name,
term_data.tid,
node.created
FROM term_data LEFT JOIN term_node ON term_node.tid = term_data.tid LEFT JOIN node on node.nid = term_node.nid WHERE node.status = 1 AND node.moderate = 0 ORDER BY node.created DESC LIMIT 0,10";
sp09’s picture

How can I set it to show random tags?