I am developing a common theme for 25 websites, the default requirements are done. Each site has got different single post template. I need to group it as a single theme so i don’t need to hard-code every time and maintain a common platform.
The various single posts template are normal-blog / tab structure / List view
I am now creating an option page for my theme, so that the user can create a layout on his own for the single-page without hardcoding(options might be drag and drop). I need to create certain components like tab,sidebar, list, and save templates for different categories. the values in tabs could be from a custom field,taxonomy. user can create n no of templates for various categories/tags/taxonomy and save it.
For Eg: Template 1 for category sports,education.
I trying to do it but i don’t have any clue to it, might be the theme atuhalpa came close. how to solve it.
It sounds like you want users to be able alter the structure of the single.php format without much WordPress know-how (perhaps it’s for clients?).
You could create an options page for this, and allow the user to select the structure they prefer.
In your
functions.php
or a plugin, you use a hook to call a function when WordPress loads a page. This function then usesis_single()
to check that if it is a single page is required, you would then get WordPress to check to see which of the single templates has been selected and then change the template being called up (which is by defaultsingle.php
if it exists). Instead it could call upsingle-normal.php
,single-tab.php
, etc (or justsingle.php
). You would then create each of these for the various format.For example:
The
single-normal.php
is perhaps superfluous, you could usesingle.php
. Also you would need to add an options page, and register the ‘single-template
‘ option with WordPress. For details see Codex’s Options Reference and creating options pages.Obviously you would have to create the files ‘
single-normal.php
‘, ‘single-tab.php
‘ etc.Edit: Or, rather than using the switch statement, you could be really clever and (if an option has been selected) simply call up the template:
'single-'.$option.'php'
, where$option
is the return of theget_option('single-template')
. This means you can always add more template-styles by creating the appropriate page, and updating the available options and the above code can remain unchanged 😀Hope this helps!
Your question is slightly unclear, but if I’m following you correctly: you need one Theme, that has several templates for
single.php
?If that’s the case, I would recommend creating the base Theme, and then using Child Themes to customize
single.php
. Doing so is the simplest way to override a single template file several times, and minimizes code repetition.