[wp-hackers] Page Templates vs Category Templates

Haluk Karamete halukkaramete at gmail.com
Fri Dec 3 20:10:49 UTC 2010


summary:

original question

i asked

	what's wrong with the following idea?
 WP CORE UI from now on allows that when you are adding a category,
you are given the same choice options ( as in the add page UI ) that
you are able to select from a number of layout options ( such as 1,2
or N col. based page layouts?
	With pages, you can pull from the Page Templates drop down a layuot
template of your choice, ( if and only if the theme designer (or
yourself) provided a proper set of page templates )
	what i was trying to point out was not having this as an option when
adding a new category is mind-boggler. as a new comer to this
interface, my and my colleques found it really puzzling.
	
mike l interpreted this very question to summarize to others

	The topic is essentially about being able to select *theme provided* layouts
	on a per category basis (similar to how you do for page templates -- and
	they could be the same ones) for people who are not up to creating/modifying
	themes.

scribu ( for the same purpose as mike l ) re-worded the question as

	perhaps the question you are really asking is: why do
	Theme developers bundle various Page templates, but don't likewise bundle
	various Category templates?
		
from these, the general reaction to the idea was received by some as

	"why do you need that? cats are different than pages. there is NO
need to do that."
	
	and by some as
	
	....
	
	some approached it from a conceptual point of view, and said

			<otto>	
			Categories, frankly, just aren't that important in the grand scheme.
			They're one (pre-defined) taxonomy out of many possible taxonomies.
			The idea needs to be generalized.
			
			More to the point though, categories, like tags, are not "things".
			They are not nouns, they are adjectives. They don't have meta-data
			because they *are* meta-data. So while yes, there's nothing
			technically difficult about giving them their own template choice
			boxes, it doesn't seem to be an effective use of the system. You'd
			have to attach meta to meta, which doesn't make any sense. Adjectives
			don't usually have their own adjectives.
			
			In a sense, Pages and Page Templates can already sorta do what you're
			suggesting. You could make a Page Template that displayed the page
			content first, followed by some selection of Posts. That selection of
			posts (what terms defined it) could be defined by some set of
			meta-data attached to the Page itself, somehow. This basically fills
			your requirements. It has its own URL, you can select the template for
			it, you can define text...
			
			There's a more generic idea here that I can't put my finger on yet.
			</otto>	
		
	i appreciated this reply cause it opened it up for me but i disagreed
with it in parts. the not agreeing part for me was his remarks that
"it does not seem to be an effective use of the system..."
	
	cause when i read it, i started thinking...
	
	if i got 100 categories ( or custom taxonomies ) that require 1 col
layout, and another 100 that require 2 col-layout, and then another
require 3 col-layout, why should i ( as a beginner who wants to use
the WP as a CMS ) do this easily from the Core UI with just 3 category
layout templates? after all, similar functionality is available right
from the core UI for pages? why does it have to be taken care of this
thru a plug in when it comes to cats? my reaction to otto's ideas was,
how come this usage does not seem to be an effective use of the
system?
	
	
			
then we got mike s who re-came in to the picture and posted this which
i thought very valuable.

	mike's solution to the problem was a quick php hack... he was
inspired from this need of mine?

	We should be able to group categories as far as layouts as well. For
	exammple, categories a,b,c,d,e,f will use 1 column lay out and cats
	t,u,x,y,z will use 4 column layout. Is that somehow possible? If so
	how?
	
	mike's php snippet was
	
		<?php // category.php
		global $wp_query;
		$term = $wp_query->get_queried_object();
		if (in_array($term->slug,array('a','b','c','d','e','f')))
		  include "category-1column.php";
		else if (in_array($term->slug,array('t','u','x','y','z')))
		  include "category-4column.php";
	
	which was disclaimed with
	
		"I've not tested this code, it's just the concept):"
		
	and philip m came up with this later;
	
		In the header at the very bottom I put a
get_template_part('layout','head'); and first line of the footer
get_template_part('layout','foot'); which handles the layout code, and
based on the user selection I wrote an if
(comicpress_is_layout('standard,vertical')) {  then handle it.  each
of the pages only contains the 'content' of those specific pages,
while the layout pages handle the sidebars etc how the content is
displayed, etc.
		Think I have 11 different layouts, most with their own widths and
some without certain sidebars etc.
		
	and mike l suggested...
	
		How about:
	
		"some UI in the theme to associate your categories with provided templates"
		
		the theme stores $cat_mappings[category-foo.php'] =>
		'no-sidebar-template.php';
		and $cat_mappings[category-bar.php'] => 'no-sidebar-template.php';
		and $cat_mappings[category-bop.php'] => 'left-sidebar-template.php';
		
		Then hook on 'category_template' filter:
		
		add_filter('category_template', 'map_category_templates');
		function 'map_category_templates'($template) {
		   if (isset($cat_mappings[$template]) )
			   return $cat_mappings[$template];
		   return $template;
		}	
	
		may need to hook locate_templates too...
		
		Damn! no filters there...
		
		No time to look into it, but theres something in there that can be done.		
		
	
of course, i was only interested in solutions from the wordpress ui
point of view, so i suggested my own solution which I see now as way
off after reading otto's initial respond in which he excellently see
the need beyond cats but more generic. after all cats are only a
specific taxonomy among many thousands way of classifying content. up
until then, i was really looking at cats as the main bread and butter.
( to a new comer, that how wp really appears, so that's not my fault!
:)) But after the educational insight, i now know and say "i can't
believe it's not butter".

Yes, the problem do call for a more generic solution.

so any time, i create or add new category or custom taxonomy, i should
be able to select a layout from a drop down exactly like the page UI
makes it happen today.

if i am creating a custom tax or a cat, i obviously plan to have a
loop that hits every single post that was associated under the current
tax at hand? well, at that level, should i have an easy choice to make
whether i use layout 1 ( say 2 col where SB on the right ) or layout 2
( where sidebar on the left ) or layout 3 ( no sidebar at all )! why
do we get into the category.php level to pull this off? ( BTW, pls
someone help me out, if i create a custom taxonomy say titled
"places", do i work with places.php, is that a convention? does wp
automatically pick it up, the same way it does as category-slug.php
gets picked up. or do i add a slug into the custom taxonomy page as
sluge=places, and call it as category-places.php? i'm in complete
black on this one. )

going back to the generic layout solution for all the custom
taxonomies, do you have any ideas as to how to pull this off? or do
you still think, no need to worry about that cause it does not really
render itself as a global need for those who want to use wp as a cms?







What about custom taxonomy X that require 1 col layout?  what about
custom taxonomy y that require 2 col layout? Should not any custom
tax. ( including cats) benefit from the  original idea of layout - so
that the solution is universal? wouldn't it be nicer to have it as a
solution so that whenever we need to add a new category/or any new
custom taxonomy, we should be able to select from layout template that
offers the same benefits and convenience that page templates offer?
	
this may require more work obviously.


	

some find the idea, it may prove useful in opening up interesting possibilites,


More information about the wp-hackers mailing list