New Event Plugin: Meta Tags

Creating and modifying plugins.
Post Reply
Matthias Melzer
Posts: 2
Joined: Tue Nov 08, 2005 7:53 pm

New Event Plugin: Meta Tags

Post by Matthias Melzer »

Hi there,
I've written several plugins the last time and now it's time to publish at least one. Nothing special(I'm surprised that nobody did it before), but it was something that came in handy, while I was doing a weblog for friends of mine. It's a metatag - plugin. I've seen that Garvin posted some day that metatags are not that important anymore, because search engines do not use them anymore (Blame me, Garvin, if I've quoted you wrong), but in the end of the day the description tag is what Google shows on the search page (otherwise it'll display the first lines of text). And all the other tags are important for Google page ranking things. And did you know that it is possible to tell Google not to cache your page anymore?

Ok, here we go. Here's the link. The Plugin is called Metainformation Standard, because I'm working on an extended version, where you can (meta-)tag your single entries. This will be the extended version then. (I've talked with a search engine optimizer guy and he said, if there is a plugin like the extended one, he will start blogging, that's a good reason to code this thing, isn't it :wink: )

http://www.matthiasmelzer.com/_other/se ... andard.zip

Let me know, what you think about it, as well as bugs and feature wishes (if there are any with meta tags).

greetz

Matthias

PS: Coding that plugin was not as hard as gathering all the informations and to provide it for the different languages :wink:
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: New Event Plugin: Meta Tags

Post by garvinhicking »

Hi!

Thanks for your effort in creating a Serendipity plugin, this is very appreciated!

I'm very interested about the feature to set a meta-tag per-entry, this would be good new functionality. Currently I think what your plugin does can also be emulated via the page_nugget/head_nugget plugin or by editing the index.tpl template file. Of course your plugin does it easier configurable and with hard-coded field name suggestions, but the problem is that our plugin repository is already getting a bit crowded so we must think hard before implementing new plugins that do something that can be done with others already.

But if it had this extended feature, it would make its place to the repository without a questions. *gg*

Great work,
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/
Matthias Melzer
Posts: 2
Joined: Tue Nov 08, 2005 7:53 pm

Post by Matthias Melzer »

Sorry, I was away the last days.

You're right. That's nothing cou can't do with the head_nugget plugin. The reason why I've developed this plugin was that I was thinking that not every new user who is downloading s9y knows about meta tags and as well how to write them into the head_nugget plugin.
Even before I would use the head_nugget plugin I would write them directly into index.tpl of the default template.
It was just meant to be kind of a service to people who are new to s9y or who are not that familiar to html at all. That's why there are so many extensive informations on the backend side of the plugin.

greetz

Matthias
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

That's alright, I hope you didn't take my writing as an offence. It was not indended as such, and I really value your service to the s9y users.

If you make progress on the extended metatags feature, I would love to get feedback by you so that we could put the plugin into the repository so that all users can easily install it, what do you think?

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/
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

I think you can use the custom entryproperties fields for this quite easily, yes!

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/
judebert
Regular
Posts: 2478
Joined: Sat Oct 15, 2005 6:57 am
Location: Orlando, FL
Contact:

Post by judebert »

I think it could be done with a plugin.

Smarty is called last, for all intents and purposes, so by the time we reach index.tpl the entries array is already set up. For both single- and multiple-entry views, the index.tpl's frontend_header plugin should get called, allowing us to add data to the <HEAD> section. In the entries.tpl template, we've already got a variable $is_single_entry telling us the mode we're in; the variable is set from includes/functions_smarty.inc.php. We can copy that piece of code for our own nefarious purposes.

So, in the plugin, we'd just add the frontend_header to our hooks, and:

Code: Select all

// Existing stuff:
if (isset($hooks[$event])) {
  switch($event) {

    // New stuff
    case 'frontend_header':
      // Single entry mode, copied from functions_smarty.inc.php
      if (isset($serendipity['GET']['id']) && is_numeric($serendipity['GET']['id'])) {
        // Get the entry
        $myEntry = array('id' => $serendipity['GET']['id']);
        serendipity_fetchEntryData($myEntry);
        // Copy it's extended tag for "meta" into the appropriate header tags
        print '<meta keywords="' . $myEntry['properties']['ep_meta'] . '">' . "\n";
      }
      return true;
      break;

  // More existing stuff
  }
}
This is my first shot at this, so I could have syntax or even intelligence errors in there, but I think this'll do it.

Let me know.
Judebert
---
Website | Wishlist | PayPal
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

You should be able to reference the $entries array from the index.tpl directory with this:

Code: Select all

{if $is_single_entry}
<meta name="description" content="{foreach from=$entries item="dategroup"}{foreach from=$dategroup.entries item="entry"}{$entry.properties.ep_metadescription}{/foreach}{/foreach}">
<meta name="keywords" content="{foreach from=$entries item="dategroup"}{foreach from=$dategroup.entries item="entry"}{$entry.properties.ep_metakeywords}{/foreach}{/foreach}">
{/if}
In pure Smarty. Using a foreach loop is unelegant, but I didn't know an easy way to get the first array index, since that is by date (like $entries.20060402.entries). Working with an array_key modified or so might work, though...

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