Ask your WordPress questions! Pay money and get answers fast! (more info)

Keep image captions attached to image when spliting post content WordPress

  • REFUNDED

I have a WP site running with the following code used to split and display the post images and content in two seperate columns -

<div class="wrapper portfolio-page-single">
<section>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<article>
<h1><?php the_title(); ?></h1>
<div class="post">
<?php
ob_start();
the_content('Read the full post',true);
$postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
ob_end_clean();
echo $postOutput;
?>
<?php //the_content() ; ?>
</div>
</article>
<aside>
<?php
preg_match_all("/(<img [^>]*>)/",get_the_content(),$matches,PREG_PATTERN_ORDER);
for( $i=0; isset($matches[1]) && $i < count($matches[1]); $i++ ) {
echo $beforeEachImage . preg_replace( '/(width|height)="\d*"\s/', "", $matches[1][$i]) . $afterEachImage;}
?>
</aside>
<?php endwhile; ?>
<?php endif; ?>
<div class="both"></div>
</section>
<div class="both"></div>
</div>


It works well, with the text displayed in the 'article' area and the images displayed in the 'aside' area. The problem is now that I am adding PayPal buttons to the images, the captions are also being stripped off the images and incorrectly displayed in the 'article' area.

How can I alter this code to keep the captions attached to the images?

I cannot provide a url to the page as it is on a private client sever.

Thanks in advance.

Answers (0)

No answers yet.