Page 1 of 1

Doing Meta keywords with Freetag

Posted: Sun Apr 16, 2006 3:01 pm
by frAgor
For those who want Meta Keywords:

If you are using Freetag Plugin, you can have set Freetag tags as Meta Keywords in your HTML header by modifying serendipity_event_freetag.php.

Register Freetag for event frontend_header, and add the follwing code to switch($event) in function event_hook:

Code: Select all

case 'frontend_header':
    $max_keywords = 20;
    if (is_int($serendipity['GET']['id'])) {
        // select tags from entry $id ordered by most usage descending
        $query = "SELECT one.tag, two.entryid, count(two.tag) AS total FROM serendipity_entrytags AS one JOIN serendipity_entrytags AS two ON two.entryid = {$serendipity['GET']['id']} AND one.tag = two.tag GROUP BY one.tag ORDER BY total DESC LIMIT $max_keywords";
    } else {
        // select most used tags in descending order
        $query = "SELECT tag, count(tag) AS total FROM {$serendipity['dbPrefix']}entrytags GROUP BY tag ORDER BY total DESC LIMIT $max_keywords";
    }
    $rows = serendipity_db_query($query);

    if (!is_array($rows)) {
        return;
    }

    echo "<meta description=\"Keywords\" content=\"";
    foreach($rows AS $r) {
        if (empty($r['tag'])) {
            continue;
        }
        $not_first ? print(', ') : $not_first = true;
        echo $r['tag'];
    }
    echo "\">";
    return true;
    break;
Now your entry detail pages will show up to $max_keywords tags in your meta keywords, ordered by the most used ones in your blog descending.
All other pages will use the $max_keywords most used tags of your blog, also in descending order.

I hope this feature can be integrated into future versions of Freetag, by setting the $max_keywords in the plugin's options (and using 0 for not displaying) or something like that.

Regards,
Markus

Re: Doing Meta keywords with Freetag

Posted: Mon Apr 17, 2006 9:09 pm
by garvinhicking
Hi Markus!

Great patch, many thanks! I just committed your patch with some modifications (the max_keywords is configurable, plus I removed a SQL injection problem).

Many thanks and best regards,
Garvin

Re: Doing Meta keywords with Freetag

Posted: Sat Apr 22, 2006 9:52 am
by frAgor
garvinhicking wrote:I just committed your patch with some modifications (the max_keywords is configurable, plus I removed a SQL injection problem).
Thank you, but there is another problem:
It has to be:
echo "<meta name="keywords" content="";
instead of:
echo "<meta description="Keywords" content="";

I'm sorry,
Markus

Re: Doing Meta keywords with Freetag

Posted: Sat Apr 22, 2006 9:12 pm
by garvinhicking
Whoops, sorry. :) Fixed :)

Regards,
Garvin