I have a page.php template and I want the first section to be wrapped in <div id="featured">
to style it differently. How do I do it?
I can’t insert the div in my template since the_content()
just outputs the whole content. I could insert the additional markup in the editor in HTML mode, but then I would have to repeat this process for every new page. Also the editor seems to insert empty p
tags for no reason..
Markup looks like this:
<img>
<p>
<p>
<p>
<P>
...
What I want is:
<div id="featured">
<img>
<p>
</div>
<p>
<p>
...
What’s the best way to do this?
Edit: Thanks for your answers. After some more searching I found exactly what I was looking for, not as straightforward as I hoped but that’s life 🙂
http://wp.smashingmagazine.com/2011/10/14/advanced-layout-templates-in-wordpress-content-editor/
A classic case for Featured images and excerpts!
You would enable both in your functions.php
Then in your tempate files (page.php for pages and single.php for posts) you would have
To make sure the excerpts and featured images are visible in the backend, in your page and post edit screen hit the ‘Screen options’ tab on the top right hand corner and from the drop down make sure that the boxes are checked. Add your text into the excerpt input box and the upload your image through the featured image dialogue box on the right.
You could filter the_content() with the WordPress API, though, i have no idea if you can accomplish this on your own. Just have a look at this Plugin
http://wordpress.org/extend/plugins/text-replace/
Which does some Search&Replace in the Content – maybe you can use it. The API for filtering the_content ist described here
http://codex.wordpress.org/Plugin_API/Filter_Reference