Doing Meta keywords with Freetag

Creating and modifying plugins.
Post Reply
frAgor
Posts: 4
Joined: Sun Apr 16, 2006 2:30 pm

Doing Meta keywords with Freetag

Post 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
s9y Blog: sAmmelsurium @ frAgwOrld
http://samsu.fragworld.de/
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Doing Meta keywords with Freetag

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
frAgor
Posts: 4
Joined: Sun Apr 16, 2006 2:30 pm

Re: Doing Meta keywords with Freetag

Post 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
s9y Blog: sAmmelsurium @ frAgwOrld
http://samsu.fragworld.de/
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Doing Meta keywords with Freetag

Post by garvinhicking »

Whoops, sorry. :) Fixed :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply