I’m creating a site that’s basically like an online book, and every post is a chapter. Each chapter gets a customized, specially designed “cover” page that can’t really be designed in the WordPress WYSIWYG. There are certain aspects of each cover that can be templatized (like an h1, h2, and single paragraph â every chapter will have that) but everything else is going to be special to each chapter. This “cover” will also have specific CSS only relevant to this chapter.
Ideally I’ll be able to design and code these covers outside of WordPress and somehow be able to inform each post which cover to use. Whether that means WordPress actually imports that code or simply includes it with a php include doesn’t much matter to me. I’d just like this to be as streamlined as possible.
Suggestions?
Another solution, that doesn’t invoke page attributes:
Explanation: To-Do List
Go and download the
RW_Meta_Box
Library. I’m one of the authors/contributers.The Plugins
Here you can see two small plugins (which I wrote especially for your question).
Input
The first one is a dependency of the RW Meta Box library. You just change what you need (User cap checks) and upload it to your plugins folder. The change you need to make is pretty simple: Search for the right User Role or Capability and add it where you currently can read
'edit_theme_options'
. It should match your designers capability but not your authors.It adds two textarea meta boxes.
Output
This one now cares about our output.
The 1st task it has is adding our styles to the
wp_head
-hook. This way, we have the possibility to inject whatever custom style the Designer adds.The 2nd thing it does is adding the current post ID to the
post_class
filter for thepost_class();
template tag. This way, we can easily target only our current post content and nothing aside it.The 3rd functionality is a parser. This parser allows your designers to add template tags via an abstraction layer: Custom
%Template Tags%
. So everything that is defined inside thewpse65707_custom_post_styles_parser
will be replaced with the set template tag. The function itself is a filter callback forthe_content
, so you don’t really have to change anything to get it working with whatever theme you’re using.Templates:
single.php
&header.php
The only things that are important to get this working with a theme are the following template tags inside those two files:
header.php
must have awp_head()
tag.single.php
must use thepost_class();
function on the post container div/article HTML tag.single.php
must usethe_content();
to display its content.How does it work now?
It’s easy: Every template tag, that is allowed inside
wpse65707_custom_post_styles_parser()
, will be exchanged with what your designer wrote.Now
%CONTENT%
gets replaced with the actual post content and%AUTHOR%
, with the authors display name. Feel free to extend it.Important is the only tag, that your designers should use to prefix their styles: The
%ID%
tag. This makes sure, that they aren’t targeting anything outside the current article container.That’s all folks!
Custom MarkUp: Post Templates
Use Page Templates.
Then simply upload a new template for each custom layout.
Custom Look: Conditional Styles
To add css to a post, just add a new stylesheet, that you enqueue only for that page.
This way, you simply can add a folder named
~/single-styles
to your theme and then add a file namedstyle-IDHERE.css
to that folder that only enqueues for that page. So it’s something along the line of contextual stylesheets.Have fun!