The following custom observer class may be of help. In theory it could be expanded to support other content types too.
However, it's based on code, not tested on a live site (I don't have the news box manager installed.)
I've highlighted in red the sections that are specific to the New Box Manager plugin. The rest is generic (but required).
It should be uploaded to /includes/classes/observers/auto.news_box_manager_metatags.php
It depends on Zen Cart v1.5.5
<?php
/**
* Adds metatags for news box manager plugin
* This module observer class is designed for Zen Cart v1.5.5 minimum.
*/
class zcObserver[B]NewsBoxManagerMetatags[/B] extends base
{
function __construct()
{
/**
* List the pages you want to override metatags for. Example: if main_page=freddy then enter 'freddy' below.
*/
$this->pages_to_override = array(
[B] 'more_news',
'news_archive',[/B]
);
/**
* Do not edit this list of attach hooks
*/
$this->attach($this, [
'NOTIFY_MODULE_START_META_TAGS',
'NOTIFY_MODULE_META_TAGS_BUILDKEYWORDS',
'NOTIFY_MODULE_META_TAGS_UNSPECIFIEDPAGE',
'NOTIFY_MODULE_META_TAGS_OVERRIDE',
'NOTIFY_MODULE_END_META_TAGS',
]);
}
/**
* Here we read $current_page, determine whether you want to override the usual generation of metatags or not, and set $meta_tags_over_ride accordingly
* When using this observer to "add" metatags for pages not already in Zen Cart, you WILL want to set $meta_tags_over_ride to true, else the 'default' will kick in.
*/
function updateNotifyModuleStartMetaTags(&$class, $eventID, $current_page, &$metatag_page_name, &$meta_tags_over_ride)
{
if (in_array($current_page, $this->pages_to_override)) $meta_tags_over_ride = true;
// if we wanted to point the metatags module to treat $current_page as some other page_name then we can set $metatag_page_name to that other page, and then we're done with it.
}
/**
* If we want to build specific keywords for this page, we do those here.
* We could pull them from database records, or language defines, etc.
*/
function updateNotifyModuleMetaTagsBuildKeywords(&$class, $eventID, $defined_custom_keywords, &$keywords_string_metatags)
{
global $db;
}
/**
* This fires in the middle of handling the "default" output if no page-specific handling was found in the metatags module.
* If you leave $meta_tags_over_ride as false here then this function is ignored.
* You CAN set $meta_tags_over_ride to true, perhaps based on the content of any of the other variables that have been passed in to this function.
*/
function updateNotifyModuleMetaTagsUnspecifiedpage(&$class, $eventID, $current_page, &$metatag_page_name, &$meta_tags_over_ride, &$metatags_title, &$metatags_description, &$metatags_keywords)
{
global $db;
if ($meta_tags_over_ride === false) return;
}
/**
* If this Observer class is being used to provide metatags for pages not already handled by Zen Cart core code, this is where you calculate that output.
* Chances are you will be pulling data from the database or from language defines.
*/
function updateNotifyModuleMetaTagsOverride(&$class, $eventID, $metatag_page_name, &$meta_tags_over_ride, &$metatags_title, &$metatags_description, &$metatags_keywords)
{
global $db;
// if we haven't already set $meta_tags_over_ride to true, then we MUST do that, else the changes made in this function will be of no effect
if ($meta_tags_over_ride === false) return;
// we can retrieve data or language defines and use those to generate $metatags_title, $metatags_description, $metatags_keywords based on $metatag_page_name
if (in_array($metatag_page_name, $this->pages_to_override)) {
[B] /**
* News box manager
* Since header_php.php has already run, we have access to the following variables, if we "global" them:
* $news_id
* $languages_id
* $news_title
* $news_content
* $start_date
* $end_date (after outputting NEWS_DATE_SEPARATOR)
*/
global $news_id, $languages_id, $news_title, $news_content, $start_date, $end_date;
$metatags_title = $news_title . ' - ' . $start_date;
$metatags_description = zen_trunc_string(zen_clean_html($news_content), 250, false);
$metatags_keywords = zen_trunc_string(zen_clean_html($news_content), 100, false);[/B]
}
}
function updateNotifyModuleEndMetatags(&$class, $eventID)
{
}
}
.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole
Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.