Site icon Hip-Hop Website Design and Development

Issue With Conditional Logic in PHP

I have made a high level custom field that permits editors to add a picture and title to be shown in a Bootstrap 3 merry go round. I’m experiencing difficulty with the contingent rationale for the picture field. The content we are utilizing is intended to utilize the picture included the high level custom field and in case there is no picture in the high level custom field it utilizes the post’s highlighted picture. The equivalent is valid for the title. On the off chance that a title is entered in the high level custom field it utilizes that. On the off chance that no title is added to the high level custom field it utilizes the post title.

The title part is functioning true to form, yet the picture part doesn’t work; it generally utilizes the highlighted picture in any event, when a picture is added to the high level custom field. I suspect there is some kind of problem with the contingent rationale utilized inside the merry go round code, yet I can not sort out what’s up. I have posted the content beneath and would see the value in any direction you can provide.

Thanks ahead of time for your help.

//Based on code initially created by Ben Blakley. See http://www.charityandbiscuits.com/blog/make bootstrap-wordpress-merry go round tagscategories-highlighted pictures/ 

/Custom circle for highlighted things in Bootstrap Carousel. 

/Slider will show posts in the 'Highlighted' classification 

/Exported PHP from Advanced Custom Fields module. Makes custom fields which are added to post, page, and occasion editors. 

if(function_exists("register_field_group")) 

{ 

register_field_group(array ( 

'id' => 'acf_featured-posts-slides', 

'title' => 'Highlighted posts slides', 

'fields' => cluster ( 

cluster ( 

'key' => 'field_5270201a54e4a', 

'name' => 'Picture', 

'name' => 'merry go round picture', 

'type' => 'picture', 

'directions' => 'Transfer a picture here on the off chance that you would prefer not to utilize the Featured Image', 

'save_format' => 'id', 

'preview_size' => 'home-slider', 

'library' => 'all', 

), 

cluster ( 

'key' => 'field_527020aa54e4b', 

'name' => 'Title', 

'name' => 'merry go round title', 

'type' => 'text', 

'directions' => 'Put a short title here on the off chance that you don't need the picture slider to utilize the Post/Page Title', 

'default_value' => '', 

'placeholder' => '', 

'prepend' => '', 

'attach' => '', 

'designing' => 'none', 

'maxlength' => 83, 

), 

), 

'area' => cluster ( 

cluster ( 

cluster ( 

'param' => 'post_type', 

'administrator' => '==', 

'esteem' => 'post', 

'order_no' => 0, 

'group_no' => 0, 

), 

), 

cluster ( 

cluster ( 

'param' => 'post_type', 

'administrator' => '==', 

'esteem' => 'page', 

'order_no' => 0, 

'group_no' => 1, 

), 

), 

cluster ( 

cluster ( 

'param' => 'post_type', 

'administrator' => '==', 

'esteem' => 'occasion', 

'order_no' => 0, 

'group_no' => 2, 

), 

), 

), 

'alternatives' => exhibit ( 

'position' => 'side', 

'format' => 'default', 

'hide_on_screen' => cluster ( 

), 

), 

'menu_order' => 0, 

)); 

} 

/Add a WordPress picture size if the slider picture size isn't as of now set in WordPress. 

add_image_size( 'home-slider', '750', '410', valid ); 

/Creates a shortcode so you can simply type [carousel] any place you need the slideshow showed. 

work carousel_shortcode(){ 

$number = 0; 

$q = query_posts( cluster ( 'category_name' => 'highlighted', 'posts_per_page' => 6, 'post_type' => exhibit ( 'post', 'page','event') ) ); 

if(have_posts()): 

/If no thumbnail or merry go round picture exists avoid it with regard to the circle to stay away from clear slides. 

/If merry go round picture set, use it, in any case utilize included picture thumbnail('home-slider). 

/If merry go round title set, use it as slide title, in any case use the_title() 

?> 

<div id="myCarousel" class="carousel slide merry go round fade"> 

<ol class="carousel-indicators"> 

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

<?php 

$postIdl = get_the_ID(); 

$has_featured_imagel = has_post_thumbnail( $postIdl ); 

$carousel_imagel = get_field('carousel-picture'); 

$carousel_image_urll = $carousel_imagel['url']; 

if($carousel_image_urll != '' || $has_featured_imagel) 

{ 

?> 

<li information target="#myCarousel" information slide-to="<?php reverberation $number++; ?>"></li> 

<?php } endwhile; ?> 

</ol> 

<!- - Carousel things - > 

<div class="carousel-inner"> 

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

<?php 

$slider_image = ''; 

$slider_title = ''; 

$postId = get_the_ID(); 

$has_featured_image = has_post_thumbnail( $postId ); 

$carousel_title = get_post_meta($postId, 'merry go round title', $single = valid); 

$carousel_image = get_field('carousel-picture'); 

$carousel_image_url = $carousel_image['url']; 

if($carousel_title != '') 

{ 

$slider_title = $carousel_title; 

} 

else 

{ 

$slider_title = get_the_title(); 

} 

if($carousel_image_url != '') 

{ 

$attachment_id = get_field('carousel-picture'); 

$size = 'home-slider'; 

$thumb = wp_get_attachment_image_src( get_field('carousel-picture'), 'home-slider' ); 

$url = $thumb['0']; 

$slider_image = '<img src="'.$url.'">'; 

} 

else 

{ 

$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'home-slider' ); 

$url = $thumb['0']; 

$slider_image = '<img src="'.$url.'">'; 

} 

if($carousel_image_url != '' || $has_featured_image) 

{ 

?> 

<div class="item"> 

<img src="<?php reverberation $url; ?>"> 

<a href="<?php the_permalink(); ?>"><div class="carousel-caption"> 

<h3 style="text-change: uppercase"><?php reverberation $slider_title; ?></h3> 

</div></a> 

</div> 

<?php } ?> 

<?php endwhile; ?> 

</div> 

<!- - Carousel nav - > 

<a id="left" class="carousel-control left" href="#myCarousel" information slide="prev"><i class="fa fa-chevron-left symbol 2x"></i></a> 

<a id="right" class="carousel-control right" href="#myCarousel" information slide="next"><i class="fa fa-chevron-right symbol 2x"></i></a> 

</div> 

<?php endif; wp_reset_query(); 

} 

add_shortcode('carousel', 'carousel_shortcode'); 

/Add js to footer. Change the span to adjust how long the slides show - 4000 equivalents 4 seconds. 

work featured_carousel() { ?> 

<script> 

jQuery(document).ready(function($){ 

$("#myCarousel .merry go round markers li:first").addClass("active"); 

$("#myCarousel .merry go round internal .item:first").addClass("active"); 

$("#myCarousel").carousel({ 

stretch: 4000 

}) 

}); 

</script> 

<?php 

} 

add_action('wp_footer', 'featured_carousel');'''