I'm after a bit of help as I'm having a bit of difficulty trying to put php code in an IF statement:
I have the following code:
<aside class="sidebar top">
<?php if(get_field('quote-text')): ?>
<div id="sidebar-testimonials">
<div class="quote-image">
<?php
$image = get_field('quote_image');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
</div>
<div id="quote-text">
"<?php the_field('quote-text'); ?>"
</div>
<span>
<?php the_field('quote-name'); ?>
</span>
</div>
<?php endif; ?>
</aside>
I'm trying to put the above code in the below code, where it says "Testimonial off" but not in the "Testimonial On" section.
<?php
$values = get_field( "display_testimonial" );
if ( $values ) {
echo "Testimonial Off";
} else {
echo "Testimonial On";
}
?>
Every time I try I'm getting PHP errors, can anyone help me out?
I have tried to merge the two codes together but I can get the sidebar to show in the else statement now:
<?php
$values = get_field( "display_testimonial" );
if ( $values ) {
?>
<aside class="sidebar top">
<?php dynamic_sidebar( 'About-Sidebar' ); ?>
<?php if(get_field('quote-text')): ?>
<div id="sidebar-testimonials">
<div class="quote-image">
<?php
$image = get_field('quote_image');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
</div>
<div id="quote-text">
"<?php the_field('quote-text'); ?>"
</div>
<span>
<?php the_field('quote-name'); ?>
</span>
</div>
<?php endif; ?>
</aside>
<?php
} else {
("<?php dynamic_sidebar( 'About-Sidebar' ); ?>");
}
?>
Thanks for your help
You have to be aware of correct opening and closing php tags:
<?php
$values = get_field( "display_testimonial" );
if ( $values ) {
// ADDED CLOSING PHP TAG
?>
<aside class="sidebar top">
<?php if(get_field('quote-text')): ?>
<div id="sidebar-testimonials">
<div class="quote-image">
<?php
$image = get_field('quote_image');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
</div>
<div id="quote-text">
"<?php the_field('quote-text'); ?>"
</div>
<span>
<?php the_field('quote-name'); ?>
</span>
</div>
<?php endif; ?>
</aside>
<?php
// ADDED OPENING PHP TAG
} else {
echo "Testimonial On";
}
?>
You have error in else part. Replace :
"Testimonial On"
to
echo "Testimonial On";
I managed to get it to work by doing the below:
<?php
$values = get_field( "display_testimonial" );
if ( $values ) {
?>
<aside class="sidebar top">
<?php dynamic_sidebar( 'About-Sidebar' ); ?>
<?php if(get_field('quote-text')): ?>
<div id="sidebar-testimonials">
<div class="quote-image">
<?php
$image = get_field('quote_image');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
</div>
<div id="quote-text">
"<?php the_field('quote-text'); ?>"
</div>
<span>
<?php the_field('quote-name'); ?>
</span>
</div>
<?php endif; ?>
</aside>
<?php
} else {
echo "<aside class='sidebar top'>";
dynamic_sidebar( 'About-Sidebar' );
echo "</aside>";
}
?>
Related
I am trying to output all client logos, but limit each section <section> to 16 logos. At the moment, the HTML outputted isn't correct but for the life of me I cannot figure our where my code is wrong.
Any help would be greatly appreciated:
<?php $logototal = count( get_sub_field('bp_client_logos') ); //Get a total count of the logos ?>
<?php
$count = "0";
if( have_rows('bp_client_logos') ) :
$i = 1;
while ( have_rows('bp_client_logos') ) : the_row(); ?>
<?php
$clientindex = $i;
if( $clientindex == "1" || ($clientindex-1) %16 == "0" ) :
?>
<div class="section general-section section-<?php echo $title; ?> section-count-<?php echo $count; ?>" data-anchor="section-<?php echo $count; ?>" style="<?php echo $bg_background; ?>">
<div class="row small-up-4 medium-up-8 large-up-8 align-middle">
<?php endif; ?>
<div class="column client-logo-grid">
<?php
$image = get_sub_field('bp_client_logo');
// Vars
$url = $image['url'];
$thistitle = $image['title'];
$alt = $image['alt'];
$caption = $image['caption'];
$size = 'ClientLogo' ;
$thumb = $image['sizes'][ $size ];
?>
<?php if ( get_sub_field('bp_client_link') ) : ?>
<a target="_blank" href="<?php the_sub_field('bp_client_link'); ?>">
<img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" />
</a>
<?php else: ?>
<img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" />
<?php endif; ?>
</div><!-- .column -->
<?php if( ($clientindex) %16 == "0") : $count = $count+1; ?>
<?php if($logototal > ($count*16)) : ?>
<div class="show-for-medium more-down-icon">
<span class="more-text">More</span> <span class="more-arrow"><img src="<?php echo get_template_directory_uri(); ?>/assets/images/arrow-down.png" alt="arrow-down-icon" /></span>
</div>
<?php endif; ?>
</div><!-- .row -->
</div><!-- .section -->
<?php endif; ?>
<?php $i++; ?>
<?php endwhile; ?>
<?php endif; ?>
If either one of $image and $content are not empty .section-intro should be output to the page. i.e if both are empty .section-intro should not output. For some reason my code isn't outputting anything to page despite at least one of the fields not being empty. Any pointers as to what I'm doing wrong would be greatly appreciated.
<?php if(have_rows('image_slideshow')):
$image = get_sub_field('image');
$content = get_sub_field('centered_text');
?>
<?php if(!empty($image) || !empty($content)): ?>
<div class="section-intro">
<div class="slides">
<?php while( have_rows('image_slideshow') ): the_row(); ?>
<div class="slide intro">
<?php if(!empty($image)): ?>
<img src="<?php echo $image['url']; ?>">
<?php endif; ?>
<?php echo $content; ?>
</div>
<?php endwhile; ?>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
construction code show be continuos like this
<?php if(have_rows('image_slideshow')):
$image = get_sub_field('image');
$content = get_sub_field('centered_text');
if(!empty($image) || !empty($content)){
echo "<div class='section-intro'> <div class='slides'>";
while( have_rows('image_slideshow') )
the_row();
echo " <div class='slide intro'> ";
if(!empty($image))
echo "<img src= $image['url'] >";
echo $content;
?>
</div>
</div>
</div>
Use AND instand of OR
<?php if(!empty($image) && !empty($content)): ?>
Also, your full code must be like this
<?php
if(have_rows('image_slideshow')):
$image = get_sub_field('image');
$content = get_sub_field('centered_text');
?>
<?php if(!empty($image) && !empty($content)): ?>
<div class="section-intro">
<div class="slides">
<?php while( have_rows('image_slideshow') ): the_row(); ?>
<div class="slide intro">
<?php if(!empty($image)): ?>
<img src="<?php echo $image['url']; ?>">
<?php endif; ?>
<?php echo $content; ?>
</div>
<?php endwhile; ?>
</div>
</div>
<?php endif ?>
Use && instead of ||
<?php if(have_rows('image_slideshow')):
$image = get_sub_field('image');
$content = get_sub_field('centered_text');
?>
<?php if(!empty($image) && !empty($content)): ?>
<div class="section-intro">
<div class="slides">
<?php while( have_rows('image_slideshow') ): the_row(); ?>
<div class="slide intro">
<?php if(!empty($image)): ?>
<img src="<?php echo $image['url']; ?>">
<?php endif; ?>
<?php echo $content; ?>
</div>
<?php endwhile; ?>
</div>
</div>
<?php endif; ?>
<?php endif; ?>
Tried several approaches but none of them work and can´t figure out what else to do. As part of a team page I have a repeater field with 4 subfields —image, title(caption),link(to trigger modal) and details(modal text content)— where some should open a modal with extra info when clicked. The modal works fine but when I try to insert a counter in the code to open the corresponding subfield for each team member, it stops working and nothing opens.
Here´s the bit of code. Any help is much appreciated.
<div class="team-block w4 clear" >
<?php
if( have_rows('team_member') ):
$counter = 1;
?>
<ul>
<?php
while( have_rows('team_member') ): the_row();
// vars
$image = get_sub_field('team_member_image');
$title = get_sub_field('team_member_title');
$link = get_sub_field('link_to_details');
$details = get_sub_field('team_member_details');
?>
<li class="team-member-box">
<?php if( $link ): ?>
<a href="<?php echo $link; ?>">
<?php endif; ?>
<img class="team-member-image" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
<?php
echo $title;
if( $link ):
?>
</a>
<?php
endif;
if( $link ):
?>
<div class="remodal team-member-details" data-remodal-id="modal<?php echo $counter;?>">
<button data-remodal-action="close" class="remodal-close"></button>
<h3>Qualifications</h3>
<p><?php echo $details; ?></p>
</div>
<?php endif; ?>
</li>
<?php
$counter++;
endwhile;
?>
</ul>
<?php endif; ?>
</div>
Check this out:
Modal №1
Modal №2
Modal №3
<div class="remodal team-member-details" data-remodal-id="modal1">
<button data-remodal-action="close" class="remodal-close"></button>
<h3>Qualifications</h3>
<p>yeah</p>
</div>
<div class="remodal team-member-details" data-remodal-id="modal2">
<button data-remodal-action="close" class="remodal-close"></button>
<h3>Qualifications</h3>
<p>yeah 2</p>
</div>
<div class="remodal team-member-details" data-remodal-id="modal3">
<button data-remodal-action="close" class="remodal-close"></button>
<h3>Qualifications</h3>
<p>yeah 3</p>
</div>
This works as expected. When I look at your code, I assume that the click on the image shoukd trigger the modal, right? I so, try this:
<div class="team-block w4 clear" >
<?php if( have_rows('team_member') ): ?>
<?php $counter = 1; ?>
<ul>
<?php while( have_rows('team_member') ): the_row();
// vars
$image = get_sub_field('team_member_image');
$title = get_sub_field('team_member_title');
$link = get_sub_field('link_to_details');
$details = get_sub_field('team_member_details');
?>
<li class="team-member-box">
<a href="modal<?php echo $counter;?>">
<img class="team-member-image" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt'] ?>" />
<?php echo $title; ?>
</a>
<?php if( $link ): ?>
<div class="remodal team-member-details" data-remodal-id="modal<?php echo $counter;?>">
<button data-remodal-action="close" class="remodal-close"></button>
<h3>Qualifications</h3>
<p><?php echo $details; ?></p>
</div>
<?php endif; ?>
</li>
<?php $counter++; ?>
<?php endwhile; ?>
</ul>
<?php endif; ?>
</div>
I am not sure if this is right (dunno what to do with the $link var) but this should work.
I am trying to build a Flexible Content which contains 4 possible Layouts (a description, a hero image, a gallery 1col and a gallery 2col). So far I can get the Description and Hero Image subfields to display just fine but the Gallery subfield wont show up on the page. Don't know what I'm doing wrong. Here's the code:
<?php
while(the_flexible_field("flexible_content")): ?>
<?php if(get_row_layout() == "description"): // layout: Description ?>
<div class="proy-desc">
<h2><?php the_sub_field("text"); ?></h2>
</div>
<?php elseif(get_row_layout() == "hero_image"): // layout: Hero Image ?>
<div class="proy-img">
<?php
$image = get_sub_field('image');
elseif( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php ?>
</div>
<?php elseif(get_row_layout() == "gallery_50p"): // layout: Gallery 50p ?>
<div class="gallery">
<?php $images = get_sub_field('gallery_image_50p');
if( $images ): ?>
<ul>
<?php foreach( $images as $image ): ?>
<li>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
</li>
<?php endforeach; ?>
</ul>
<?php ?>
</div>
<?php endif; ?>
<?php elseif(get_row_layout() == "gallery_100p"): // layout: Gallery 50p ?>
<div class="gallery">
<?php $images = get_sub_field('gallery_image_100p');
if( $images ): ?>
<ul>
<?php foreach( $images as $image ): ?>
<li>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
</li>
<?php endforeach; ?>
</ul>
<?php ?>
</div>
<?php endif; ?>
<?php endif; ?>
<?php endwhile; ?>
You did not close your if statement. See below:
<?php elseif(get_row_layout() == "gallery_50p"): // layout: Gallery 50p ?>
<div class="gallery">
<?php $images = get_sub_field('gallery_image_50p');
if( $images ): ?>
<ul>
<?php foreach( $images as $image ): ?>
<li>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
</li>
<?php endforeach; ?>
</ul>
<?php ?>
</div>
<?php endif; ?>
Change your section to this:
<?php elseif(get_row_layout() == "gallery_50p"): // layout: Gallery 50p ?>
<div class="gallery">
<?php $images = get_sub_field('gallery_image_50p');
if( $images ): ?>
<ul>
<?php foreach( $images as $image ): ?>
<li>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
Your endif; was in the wrong spot. Everything else looks right, so give this a try.
Need to make linkable images with Camera Slideshow. url must be received from Url_A in material.
in _item.php
<div class="camera-item" data-src="<?php echo htmlspecialchars($images->image_intro); ?>">
I tried to do
<?php $urls = json_decode($item->urls); ?>
<a href="<?php echo $urls->urla;?>">
<div class="camera-item" data-src="<?php echo htmlspecialchars($images->image_intro); ?>">
</div></a>
but got error. Help to novice please! and sorry for bad english :)
21.08
Full code of _item.php with some changes
<?php
defined('_JEXEC') or die;
$images = json_decode($item->images);
$urls = json_decode($item->urls);
$slider_img = htmlspecialchars($images->image_intro);
?>
<div class="camera-item" rel="<?php echo $urls->urla;?>" data-src="<? echo $slider_img; ?>">
<?php if ($params->get('show_caption')): ?>
<div class="camera_caption <?php echo $params->get('captionEffect'); ?>">
<?php $item_heading = $params->get('item_heading', 'h4'); ?>
<?php if ($params->get('item_title')) : ?>
<<?php echo $item_heading; ?> class="slide-title<?php echo $params->get('moduleclass_sfx'); ?>">
<?php if ($params->get('link_titles') && $item->link != '') : ?>
<a href="<?php echo $item->link;?>">
<?php echo $item->title;?></a>
<?php else : ?>
<?php echo $item->title; ?>
<?php endif; ?>
</<?php echo $item_heading; ?>>
<?php endif; ?>
<?php if (!$params->get('intro_only')) :
echo $item->afterDisplayTitle;
endif; ?>
<?php echo $item->beforeDisplayContent; ?>
<?php echo $item->introtext; ?>
<?php if (isset($item->link) && $item->readmore != 0 && $params->get('readmore')) :
echo '<a class="readmore" href="'.$item->link.'">'.$item->linkText.'</a>';
endif; ?>
</div>
<?php endif; ?>
</div>
I got url to atribute rel but still can't make clickable images :(
In firebug
<div id="camera-slideshow" class="camera_wrap" style="height: 755px;">
<div class="camera_fakehover">
<div class="camera_src camerastarted camerasliding">
<div class="camera-item" data-src="images/slide1.jpg" rel="/index.php/urla"> </div>
<div class="camera-item" data-src="images/slide2.jpg" rel="/index.php/urla"> </div>
<div class="camera-item" data-src="images/slide3.jpg" rel=""> </div>
</div>
source code
<div class="camera-item" rel="/index.php/urla" data-src="images/slide1.jpg">
<div class="camera_caption fadeIn">
<div class="txt1">some text</div>
<div class="txt2">some text</div>
</div>
</div>