Adding categories to newsticker
Midgard CMS contains a powerful PHP-level data abstraction layer called datamanager. With datamanager it is possible to freely modify the content fields and editing widgets used with any MidCOM component using custom schemas.
The first thing when adding new categories is to make the category field array. As an example example:
"categories" => array
(
"description" => "Categories",
"datatype" => "text",
"location" => "parameter",
"widget" => "multiselect",
"multiselect_selection_list" => array
(
"Midgard" => "Midgard",
"Travel" => "Travel",
"Security" => "Security",
),
),
What you need to do next is to copy the default de.linkm.newsticker schema from the config/schemadb_default.inc file of the component to the sitegroup-config/de.linkm.newsticker snippet directory and add your own field definition there.
It is the area starting with:
"default" => array (
"name" => "default",
"description" => "News Article",
...
Copy that area into a text editor (or just your clip board), and add the category block you've made into the fields array. A good place to do that would be between title and abstract.
Then you need to store this new schema definition into your Midgard setup as a snippet.
Go to Aegir, select the Snippet tab from the left, and create a snippet directory named sitegroup-config. Then under that create another snippet directory named de.linkm.newsticker by clicking New on the right-hand frame's menu.
This is the default location used for MidCOM's configuration. You don't need to follow that convention but I'd recommend it.
Now that you have the snippetdirs created, click New (again in the right-hand frame), and create a snippet named schema, and paste your schema array there.
Then you need to configure your newsticker to use the new schema. Here you have two options, either set it to be used by all de.linkm.newsticker folders on your site, or only a particular folder.
To use it for all newstickers, create another snippet named config in the /sitegroup-config/de.linkm.newsticker directory, and in that snippet place the following:
"schemadb" => "/sitegroup-config/de.linkm.newsticker/schema",
If you want to enable it for only one newsticker folder (or override the default specified above), you can do this by going to the newsticker folder on site, and clicking the Component configuration toolbar item. Scroll down the form, and enter your schema's path in the Path to the schema database field:
/sitegroup-config/de.linkm.newsticker/schema
Now your folder should have categories enabled for its all news items. If you are using a desktop blog editor The categories will also appear in the RSS feed generated from your news folder.
Displaying categories on site
With this work, the categories won't yet appear on your site. For that you need to modify the output templates of your blog.
The relevant templates for de.linkm.newsticker are show-index-item and show-detail. Create your own copies of those under the substyle used by your newsticker and add something like the following:
<?php
if ($view['categories'])
{
echo "<p>Filed under";
foreach ($view['categories'] as $category)
{
echo "{$category}, ";
}
}
?>
Related
- Creating custom Datamanager schemas
- Using MidCOM template to load schema variables
- Modifying MidCOM component output
