mercredi 4 mars 2015

Filtering the_content, but still need to display the unfiltered content inside filter


I'm working on a plugin that creates and displays Custom Post Types. I'm using ACF for additional fields.


Problem comes when I need to add the actual content into the filter. There's a slideshow in the normal wysiwyg editor that needs to be displayed there. See screengrab.


Is there a way to have the_content be displayed inside a filter that is using the_content? Or is there a different way of coding this?


Here is my code:



add_filter('the_content', 'fds_the_content');
function fds_the_content( $content ) {

if (is_singular( 'services' ) && in_the_loop()) {
ob_start(); ?>

<div class="fds-top">

<div id="top-content" class="contain-columns">

<div id="portfolio" class="m-all t-2of3 d-3of4 gl">

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<div class="slideshow">

<section class="entry-content cf">
<?php the_content(); ?>
</section> <!-- end article section -->

</div>

<?php endwhile; ?>

<?php else : ?>

<?php endif; ?>

</div> <!-- end #portfolio -->
<div class="2-percent"></div> <!-- What a hack! -->
<div id="service-sidebar" class="m-all t-1of3 d-1of4 gl">

<h2>Recent
<?php
$category = get_the_category();
echo $category[0]->cat_name;
?>
</h2>

<?php
global $post;
$categories = get_the_category();
foreach ($categories as $category) :
?>

<?php
// The Query
$the_query = new WP_Query(

array(
'posts_per_page' => 2,
'category__and' => array( $category->term_id ) ) );
?>
<?php if ( $the_query->have_posts() ) : ?>


<!-- the loop -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<a class="recent-post" href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>" >
<div class="recent-thumb"><?php the_post_thumbnail('medium'); ?></div>
<h3 class="recent-blog-title-desktop"><?php the_title(); ?></h3>
</a>

<?php endwhile;
wp_reset_query(); ?>
<!-- end of the loop -->

<!-- pagination here -->
<?php wp_reset_postdata(); ?>

<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>



<?php endforeach; ?>

</div>
</div>

<div class="clear"></div>

<div id="midriff" class="contain-columns">

<div id="service-info" class="m-all t-all d-all gl">
<header class="article-header">
<h1 class="single-title custom-post-type-title"><?php the_title(); ?></h1>
</header>

<section class="entry-content cf">

<div class="segment">
<div class="segment-photo-left">
<?php
$image = get_field('general_photo');
$size = 'medium'; // (thumbnail, medium, large, full or custom size)
if( $image ) {
echo wp_get_attachment_image( $image, $size );
}
?>
</div>
<div class="segment-text"><?php the_field('general_info'); ?></div>
</div>

<div class="segment">
<h2>Rates</h2>
<div class="segment-photo-right">
<?php
$image = get_field('rates_photo');
$size = 'medium'; // (thumbnail, medium, large, full or custom size)
if( $image ) {
echo wp_get_attachment_image( $image, $size );
}
?>
</div>
<div class="segment-text"><?php the_field('rates'); ?></div>
</div>

<div class="segment">
<h2>Areas Served</h2>
<div class="segment-photo-left">
<?php
$image = get_field('areas_served_photo');
$size = 'medium'; // (thumbnail, medium, large, full or custom size)
if( $image ) {
echo wp_get_attachment_image( $image, $size );
}
?>
</div>
<div class="segment-text"><?php the_field('areas_served'); ?></div>
</div>

<div class="segment">
<h2>Kind Words</h2>

<?php

// args
$args = array(
'posts_per_page' => 1,
'post_type' => 'reviews',
'meta_key' => 'review',
'orderby' => 'rand'
);

// get results
$the_query = new WP_Query( $args );

// The Loop
?>
<?php if( $the_query->have_posts() ): ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<blockquote>

<?php the_field('review'); ?>

</blockquote>
<h3 class="client-sig">~<?php the_field('review_client_name'); ?></h3>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>

</div>

<div class="segment">
<h2>Contact</h2>
<div class="segment-photo-right">
<?php
$image = get_field('contact_photo');
$size = 'medium'; // (thumbnail, medium, large, full or custom size)
if( $image ) {
echo wp_get_attachment_image( $image, $size );
}
?>
</div>
<div class="segment-text"><?php the_field('contact'); ?></div>
</div>

</section>

</div> <!-- End #service-info -->

</div>

</div>

</div>


<?php
echo ob_get_clean();
}
return $content;
}


This shows the output from above code





Aucun commentaire:

Enregistrer un commentaire