I've got a weird layout to get around and am at a loss, even in the planning stage. Essentially I need to separate out all content that's not a .gallery
and put it into an <aside />
. I initially considered a plugin using the edit_post
hook from the Plugin API, but have since decided against it because this content change is layout specific and I want to maintain a clean database. So...
How can I parse through WP's the_content
for content that's not .gallery
? Admittedly not a PHP guy, so I doubly appreciate the help!
As per Michael's comment below - here's an example of WP's the_content
class output:
HTML
<div class="entry-content">
<div class="gallery">
<dl class="gallery-item">
<dt class="gallery-icon portrait">
<img src="/imagePath/etc.jpg" class="attachment-thumbnail">
</dt>
</dl>
<dl class="gallery-item">
<dt class="gallery-icon portrait">
<img src="/imagePath/etc.jpg" class="attachment-thumbnail">
</dt>
</dl>
<dl class="gallery-item">
<dt class="gallery-icon portrait">
<img src="/imagePath/etc.jpg" class="attachment-thumbnail">
</dt>
</dl>
</div>
<p>Curabitur vulputate, ligula lacinia scelerisque tempor, lacus lacus ornare ante, ac egestas est urna sit amet arcu. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed molestie augue sit amet.</p>
<ul>
<li>Item A</li>
<li>Item B</li>
<li>Item C</li>
</ul>
</div>
Desired Output
<div class="entry-content">
<div class="gallery">
<dl class="gallery-item">
<dt class="gallery-icon portrait">
<img src="/imagePath/etc.jpg" class="attachment-thumbnail">
</dt>
</dl>
<dl class="gallery-item">
<dt class="gallery-icon portrait">
<img src="/imagePath/etc.jpg" class="attachment-thumbnail">
</dt>
</dl>
<dl class="gallery-item">
<dt class="gallery-icon portrait">
<img src="/imagePath/etc.jpg" class="attachment-thumbnail">
</dt>
</dl>
</div>
<aside>
<p>Curabitur vulputate, ligula lacinia scelerisque tempor, lacus lacus ornare ante, ac egestas est urna sit amet arcu. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed molestie augue sit amet.</p>
<ul>
<li>Item A</li>
<li>Item B</li>
<li>Item C</li>
</ul>
</aside>
</div>
Maiorano84's answer worked beautifully, but prior to his reply I worked out an alternate method that's less specific to my situation, so I figured it'd be good to share.
I had originally written off the plugin approach because it requires changing post content itself - not just the format of the output, but realized that plugins live independent of the theme installation. Below is a very simple, developer targeted plugin that converts a
[aside /]
shortcodes intoHTML
elements. It's entirely based on BSD Aside by Sean D Burkin. I'll eventually include a button for the WP text editor and open source it.You'll want to use a Dom Parser for this. Here's an example in how you can go about it using your markup as an example. Testing yielded the desired results, so hopefully this will give you the head start you need: