Page 1 of 1

Using as a CMS

Posted: Fri Dec 29, 2006 4:21 pm
by davidlowry
I have written a css/xhtml/javascript menu system and wish to integrate with Serendipity. If someone could point me where to get the bits n' pieces i need....

My menu example is here: http://cathedral.dromore.anglican.org/cathedral07/

You can see the five or six sections or 'categories'. So I want Serendipity to give me out:

Code: Select all

[foreach] Category {
  [for 1-5] { - Item }
}
Do I need to write a plugin for this? Is a plugin just a fancy name for a tpl template? Any hints ?

Thanks v much!

Posted: Fri Dec 29, 2006 6:08 pm
by judebert
Nice menu.

A plugin is actually PHP code that can be executed by Serendipity within the application context. As such, plugins get access to all the Serendipity variables and functions. Templates (which are implemented in Smarty) only get access to a subset of these variables and functions.

The categories plugin is templatized, though. You can check it out in {your_template_directory}/plugin_categories.tpl. If that file doesn't exist, then Serendipity will use the one in the templates/default/ directory; copy it into {your_template_directory} so your changes don't affect other templates.

You can see that it uses this code:

Code: Select all

{foreach from=$categories item="plugin_category"}
        <li style="display: block;">
        {if $is_form}
            <input style="width: 15px" type="checkbox" name="serendipity[multiCat][]" value="{$plugin_category.categoryid}" />
        {/if}

        {if !empty($category_image)}
            <a class="serendipity_xml_icon" href="{$plugin_category.feedCategoryURL}"><img src="{$category_image}" alt="XML" style="border: 0px" /></a>
        {/if}

            <a href="{$plugin_category.categoryURL}" title="{$plugin_category.category_description|escape}" style="padding-left: {$plugin_category.paddingPx}px">{$plugin_category.category_name|escape}</a>
        </li>
{/foreach}
You seem to have some experience in Smarty templating, but just in case: note that each {if} is matched with an {/if}, and each {foreach} has a matching {/foreach}. The stuff between the {foreach} blocks is printed once for every entry in the $categories variable. Within the {foreach}, the individual category information will be called $plugin_category. You can see that there are categoryURL and category_name attributes that you can use, along with a few others.

Just replace all the stuff between the {foreach} with the data required by your menu code, and you're good to go.

Posted: Fri Dec 29, 2006 6:48 pm
by davidlowry
Thanks Jude that's great. So here's where I am!

Code: Select all

<div id="serendipity_categorymenu">
    <ul id="nav">
{foreach from=$categories item="plugin_category"}
        <li>
			<div><a href="{$plugin_category.categoryURL}"
					title="{$plugin_category.category_description|escape}">{$plugin_category.category_name|escape}</a>
			</div>
			<ul>
				<li><a href="#">blah</a></li>
			</ul>	
        </li>
{/foreach}
    </ul>
</div>
Confused again, however :-) As the plugins have a place in the CMS Admin, they have properties, etc. Do I just ignore those and override the Categories template (by putting the file in my customised template folder).

Also as you can see I have this dummy in place:

Code: Select all

			<ul>
				<li><a href="#">blah</a></li>
			</ul>	
I'm assuming I'll need to write a new template to handle each category news item (or hack an old one, assumably: entries_summary.tpl or something similar).

Do I take this plugin, just stick in the folder and reference it (as before like this: {foreach from=$categories item="plugin_category"}
ie

Code: Select all

<ul>
 {foreach from=$entries item="plugin_entries_by_cat"}
   <li><a href="plugin...url">plugin_entries_by_cat.entryName</li>
 {/foreach}
) or is there anything whizz-bang I needa do to make 'plugin_entries_by_cat' work?

Apologies for the confusion and so on! Thanks for your help.

(re Menu, thanks - 2.5 days with a bit of sniffing thru Jeremy Keith's book did the trick, am going to do a tutorial on it once this site is all over!)

Posted: Wed Jan 03, 2007 4:49 pm
by judebert
I'm not understanding what you want, so I can't answer the question effectively. What do you want to go in the blah?

Posted: Tue Jan 09, 2007 12:27 am
by davidlowry
:-)
I've worked around it for now; I may return and bump this thread whenever I come back to do the job properly!!!

Thanks for the asst. judebert