Skip Navigation

[Résolu] Featured image caption not displayed properly when using theme template

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 4 réponses, has 2 voix.

Last updated by Eric Il y a 8 années et 1 mois.

Assigned support staff: Luo Yang.

Auteur
Publications
#118036

Hello,

I have a custom field group that uses a WYSIWYG field. I have a Content Template that displays it, and it works great. For my Events post type, however, which is outside the Types plugin, I've had to create a php template for single events. I'm able to display all the data from my custom fields in it, but there are two little glitches...

On images with captions, wordpress automatically wraps those in a div with the wp-caption class, but sadly that's not happening in my php template. Also, the <p> tags that wordpress auto-inserts inside blockquotes aren't appearing on pages that use the php template either.

Here's a code example from my custom WYSIWYG field that gets generated (correctly) by my Content Template:

<div id="attachment_405" class="wp-caption alignright" style="width: 345px">
     <img class="size-full wp-image-405" alt="My Img Alt" src="myimg.jpg" width="345" height="231">
     <p class="wp-caption-text">My Image Caption</p>
</div>

<blockquote>
     <p>This is my blockquote</p>
</blockquote>

Here's how that same WYSIWYG field looks when using my php template (note the missing container elements):

<img class="size-full wp-image-405" alt="My Img Alt" src="myimg.jpg" width="345" height="231">
My Image Caption

<blockquote>This is my blockquote</blockquote>

Here's how I'm calling it in the php template:

<?= types_render_field("free-form-content") ?>

I've tried adding various parameters, but nothing will add the p-tag back into the blockquote or apply the outer container div to the image with caption.

Any ideas?

Thanks

#118164

Luo Yang
Supporter

Languages: Anglais (English ) Chinois simplifié (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hi Eric,

I can not duplicate same problem in my localhost, and I suggest you try calling it in the php template:

<?php 
$parameters = array(
	'raw'=> true,
);
echo types_render_field("free-form-content", $parameters ); 
?>

Parameters:‘raw’ => ‘true’|'false’ (display raw data stored in DB, default false)
https://toolset.com/documentation/functions/#WYSIWYG

#118171

Hi Iuoy,

I tried your solution, but no luck. The auto-p tags were not inserted into my blockquote, and now the wordpress-generated shortcode for wrapping a captioned photo is actually printing on the page around my image like so:

[caption id="attachment_736" align="alignnone" width="345"]KTAR Give-a-Thon[/caption]

Would it help you to see the all the code for my php template? If so, I'll copy it in.

#118418

I'm copying in my template code. Maybe you can see something that might be causing the problem. The WYSIWYG custom field that no longer outputs photo captions correctly is near the top.


<? get_header() ?>


<!-- WP Content -->
<?php if (have_posts()) : while (have_posts()) : the_post();?>
	<? $event = em_get_event($post->ID) ?>
	<? $location = em_get_location($event->location_id) ?>

		<div class="eight columns">
			<?= get_the_post_thumbnail($event->ID, 'event-header') ?>
			<div class="main-image">
				<img class="detail-pg-main-photo" src="<?= types_field("main-photo") ?>" />
			</div>
			<div class="story">
				<?= the_content() ?>
				<h2><?= types_field("headline") ?></h2>
				
				<?//= types_render_field("free-form-content") ?>

				<?// WYSIWYG ?>
				<?php 
				$parameters = array(
				    'raw'=> true,
				);
				echo types_render_field("free-form-content", $parameters ); 
				?>
				
				
				<? $vid_single = types_field("video-url");
				   $vid_multi = types_field("video-slider-id");
				   $vid_caption = types_field("video-caption");
				   
				if ((!is_null($vid_single)) || (!is_null($vid_multi))) : ?>
				
				<div class="video wp-caption clear">
				
					<? if (!is_null($vid_single)) : ?>
				
						<iframe width="690" height="388" src="//www.youtube.com/embed/<?= types_field('video-url', array('raw'=>'true')); ?>" frameborder="0"></iframe>
					
					<? endif; ?>
				
					<? if (!is_null($vid_multi)) : ?>
				
						<? $video_slider_id = types_field("video-slider-id", array("format"=>"FIELD_VALUE")); ?>
				
						<? echo do_shortcode("[slider_pro id='$video_slider_id']"); ?>
				
					<? endif; ?>
					
					<? if (!is_null($vid_caption)) : ?>
					
						<p class="wp-caption-text"><?= types_field("video-caption");?></p>
					
					<? endif; ?>
				
				</div>
				
				<? endif; ?>
				
				<?= types_field("free-form-content-2") ?>
			</div>
		</div>
		<div id="sidebar-primary" class="four columns text-center">
			<div class="panel">
			
				<?// EVENT NAME ?>
				<div class="title"><h1><?= $event->event_name ?></h1></div>
				
				<?// SHARETHIS ?>
				<?php echo do_shortcode("[share-this-buttons]"); ?>

				<?// PRIMARY BUTTON (RED) ?>
				<a class="button primary huge red gradient expand" href="<?= types_field('primary-button-url') ?>">
					<span><?= types_field("primary-button-text", "Purchase Tickets") ?></span>
				</a>
				
				<?// EVENT DETAILS - DATE TIME ?>
				<h6 class="uppercase">Details</h6>

				<h2 class="caps"><?= $event->event_name ?></h2>

				<p class="date">
					<span class="weekday"><?= display_formatted_date($event->start_date, "%A") ?></span>
					<span class="cal-date"><?= display_formatted_date($event->start_date, "%B %e, %Y") ?></span>
					<span class="time"><?= display_formatted_date($event->start_time, "%l%p") ?>
					-
					<?= display_formatted_date($event->end_time, "%l%p") ?></span>
				</p>

				<?// LOCATION ?>
				<div class="location">
					<span class="venue"><?= $location->location_name ?></span>
					<span class="address"><?= $location->location_address ?></span>
					<span class="town"><?= $location->location_town ?>, <?= $location->location_state ?> <?= $location->location_postcode ?></span>
				</div>
				
				<?// DONATE ?>
				<? $donate_url = types_field('donate-url', null, false); ?>
				<? if (!is_null($donate_url)): ?>
				<hr />
				<a href="<?= types_field('donate-url') ?>" class="button huge blue solid expand">
					<span><?= types_field('donate-text') ?></span>
				</a>
				<? endif; ?>
							
				<?// SECONDARY BUTTON (BLUE) USING FOR DONATE ?>
				<? $secBtn_lead = types_field("secondary-button-lead-in-text");
				   $secBtn_text = types_field("secondary-button-text");
				   $secBtn_url = types_field("secondary-button-url");
				   if (!is_null($secBtn_url)) : ?>
				   		<hr />
				   		<? if (!is_null($secBtn_lead)) : ?>
				   			<h3><?= types_field("secondary-button-lead-in-text"); ?></h3>
				   		<? endif; ?>
				   		<a class="button secondary huge blue solid expand" href="<?= types_field('secondary-button-url') ?>">
					   		<span><?= types_field("secondary-button-text") ?></span>
					   	</a>	
				   	<? endif; ?>
				   	
				<?// CONTACT ?>		
				<? $email = types_field('email-address');
				   $phone = types_field('phone-number');
				   if ((!is_null($email)) || (!is_null($phone))) : ?>
				
					<h6 class="uppercase">Contact</h6>
					
					<? if (!is_null($phone)) : ?>
						<h3>
							<?= types_field("phone-number") ?>
						</h3>
					<? endif; ?>
					
					<? if (!is_null($email)) : ?>
						<a class="button blue solid heavy expand" href="mailto:<?= types_field('email-address') ?>">
							<?= 'Email ' . $event->event_name ?>
						</a>
					<? endif; ?>
					
				<? endif; ?>

				<?// CO-CHAIRS ?>
				<? $cochairs = types_field('co-chairs', null, false) ?>
				<? if (!is_null($cochairs)): ?>

					<h6>Co-Chairs</h6>

					<?= types_field('co-chairs', null, false) ?>
				<? endif; ?>
				
				<?// SPONSORSHIP ?>
				<? $sponsorship_url = types_field('sponsorship-url', null, false) ?>
				<? if (!is_null($sponsorship_url)): ?>
					<hr />
					<? $sponshorship_info = types_field('sponsorship-information', null, false); ?>					
					<? if (!is_null($sponshorship_info)): ?>

						<h3><?= types_field('sponsorship-information', null, true) ?></h3>
						
					<? endif; ?>
	
					<a href="<?= types_field('sponsorship-url')?>" class="button blue solid heavy expand">
						<?= types_field('sponsorship-block_button-text', 'Sponsor This Event') ?>
					</a>
						
				<? endif; ?>
				
				<?// WYSIWYG ?>
				<? $ff_sidebar_content = types_field('free-form-content-for-sidebar', null, false) ?>
				<? if (!is_null($ff_sidebar_content)): ?>
					<hr />
					<?= types_field('free-form-content-for-sidebar', null, false) ?>
				<? endif; ?>
				
			</div>
		</div>

<?php endwhile; endif; ?>

<? get_footer() ?>


#118589

Got it to work like so:

<?php 
	$parameters = array(
	    'raw'=> true
	);
	echo do_shortcode(types_render_field("free-form-content", $parameters )); 
?>

Hope this helps somebody...