how to make this picture in wordpress loop with owl carousel - php

I need to create something like this in my picture, i want to do this with php, something like this
$count = 0;
while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="item">
<?php if( $count == 1 ) { echo '<div class="col-sm-6">'; } ?>
<?php echo '<div class="col-sm-6">'; ?>
<img src="sample">
<?php echo '</div>'; ?>
<?php if( $count == 1 ) { echo '</div>'; } ?>
</div>
<?php $count++; endwhile
with bootstrap like this :
<div class="owl-carousel">
<div class="item">
<div class="col-sm-6">
<div class="col-sm-12">
<img src="sample">
</div>
<div class="col-sm-12">
<img src="sample">
</div>
</div>
<div class="col-sm-6">
<img src="sample">
</div>
</div>
</div>
my code is wrong, i know, i need an Idea, how to do this, thank you

You have to do this in 2 parts first you have to build an associative array which will contain all 12 images URL, then you can loop through that array to display the images
1st part to built an array:
$owl_array = [];
$args = array(
'post_type' => 'post',
'post_status' => 'publish'
);
$query = new WP_Query($args);
if (!empty($query->posts)) {
foreach ($query->posts as $key => $post) {
//custom logic to get the image URL
$thumb_id = get_post_thumbnail_id($post->ID);
$thumb_url_array = wp_get_attachment_image_src($thumb_id, 'thumbnail', true);
$owl_array[++$key] = (!empty($thumb_url_array[0])) ? $thumb_url_array[0] : 'http://example.com/default-image.jpg'; //assiging each featured image url into owl_array
}
}
//print_r($owl_array);
2nd part to diplay owl carousel:
<div class="owl-carousel">
<?php for ($i = 1; $i <= count($owl_array); $i++) { ?>
<div class="item">
<div class="col-sm-6">
<div class="col-sm-12 1">
<img src="<?php echo $owl_array[$i]; ?>">
</div>
<div class="col-sm-12 2">
<?php
$i++; //increment the counter
?>
<img src="<?php echo $owl_array[$i]; ?>">
</div>
</div>
<div class="col-sm-6 3">
<?php
$i++; //increment the counter
?>
<img src="<?php echo $owl_array[$i]; ?>">
</div>
</div>
<?php } ?>
</div>

Related

php template code - all properties page display issue

My page: http://kevinkang.ca/en_US/all-properties/ was broken yesterday.
But I can't find any problem on these. Can anyone help me to find out the problem?
<div class="grid-x all-properties-page">
<?php
$args = array( 'category__not_in' => array( 4, 8, 9, 10 ) , 'posts_per_page' => -1 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php $i=0; ?>
<div class="medium-12 cell padding-top-page">
<div class="home-data description-title-price">
<div class="grid-container">
<div class="grid-x">
<div class="medium-6 cell">
<?php the_title(); ?>
</div>
<div class="medium-6 cell text-right">
<?php the_field('price'); ?>
</div>
</div>
</div>
</div>
<a href="<?php the_permalink(); ?>"><div class="grid-x">
<ul class="images3">
<?php
//Get the images ids from the post_metadata
$images = acf_photo_gallery('3-images', $post->ID);
$img3=0;
if( count($images) ):
//Cool, we got some data so now let's loop over it
foreach($images as $image):
$id = $image['id']; // The attachment id of the media
$title = $image['title']; //The title
$caption= $image['caption']; //The caption
$full_image_url= $image['full_image_url']; //Full size image url
$full_image_url = acf_photo_gallery_resize_image($full_image_url, 1562, 760); //Resized size to 262px width by 160px height image url
$thumbnail_image_url= $image['thumbnail_image_url']; //Get the thumbnail size image url 150px by 150px
$url= $image['url']; //Goto any link when clicked
$target= $image['target']; //Open normal or new tab
$alt = get_field('photo_gallery_alt', $id); //Get the alt which is a extra field (See below how to add extra fields)
$class = get_field('photo_gallery_class', $id);
$img3++;
?>
<?php if( !empty($url) ){ ?><a href="<?php echo $url; ?>" <?php echo ($target == 'true' )? 'target="_blank"': ''; ?>><?php } ?>
<li style="background-image: url(<?php echo $full_image_url; ?>);" class="img-list<?php echo $img3; ?>">
<?php if( !empty($url) ){ ?></a><?php } ?></li>
<?php endforeach; endif; ?>
</ul>
<?php foreach ( get_the_category() as $value) {
$i++; ?> <h3 class="cat<?php echo $i; ?> <?php echo $value->name; ?>"><?php echo $value->name;} ?></h3>
</div></a>
<div class="grid-container pr-address-bg">
<div class="address-cont price-address">
<?php the_field('price'); ?>
<?php the_field('address_first_line'); ?>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
I see you have a lot of problems in your HTML ( inside , multiple tags. First check your HTML with https://validator.w3.org/. It looks the main parts of the problems come from header.php. I would have a look.

PHP Wrapping custom items inside loop Wordpress

I am currently creating a slider which consists of products.
Currently I have managed to wrap every 2 items in div using this code:
<div class="frame crazy" id="crazy">
<div class="slidee">
<?php if ( $myposts->have_posts() ) :
$i = 0;
while ( $myposts->have_posts() ) : $myposts->the_post();
$image = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_id() ), 'single-post-thumbnail' );
$value = get_field( "alternate_image", get_the_id() );
$titl = get_field( "title", get_the_id() );
$big = get_field( "big_section", get_the_id() );
if ( $i % 2 == 0) : ?>
<div class="op" <?if ($big==1){?>style="width:850px !important;"<?}?>>
<?php endif;
$_pf = new WC_Product_Variable(get_the_id());
$variations = $_pf->get_available_variations();
$vrt = count($variations);
?>
<div data-hv="<?php echo $value; ?>" data-titleContent="<a href='<?php echo get_the_permalink();?>'><?php echo get_the_title(); ?></a>" data-tipso-content="<span class='varaition'>this item has <?php echo $vrt; ?> variation(s)</span><a class='bty' href='<?php echo get_the_permalink(); ?>'>details</a>" data-url="<? echo the_permalink(); ?>" class="cola <?php if($big==1){?>big<?}?>" style="background-image: url('<?php echo $image[0]; ?>')" data-mg="<?php echo $image[0];?>">
<?php if($titl==1) { ?>
<h2><a href='<?php echo get_the_permalink();?>'><?php echo get_the_title(); ?></a></h2>
<p class="slu"><a href='<?php echo get_the_permalink();?>'>shop now ></a> </p>
<?php } ?>
</div>
<?php if ( $i % 2 != 0 ) : ?>
</div>
<?php endif; ?>
<?php $i++; endwhile; ?>
<?php if ( $i % 2 != 0 ) : ?>
</div>
<?php endif; ?>
<?php endif;?>
</div>
</div>
This code wraps every two products like this:
<div class="op">
<div class="product1">
//content
</div>
<div class="product2">
//content
</div>
</div>
<div class="op">
<div class="product3">
//content
</div>
<div class="product4">
//content
</div>
</div>
But I need to fetch custom number of posts according to product meta. So that the number of products can be varying like this:
<div class="op">
<div class="product1">
//content
</div>
<div class="product1">
//content
</div>
<div class="product1">
//content
</div>
<div class="product1">
//content
</div>
<div class="op">
<div class="product1">
//content
</div>
<div class="product1">
//content
</div>
</div>
Is it possible using product meta or any better idea?
this line in your code:
if ( $i % 2 == 0) : ?>
contains the loop number, change that to be a variable and set that variable from the meta data, so:
$loopmeta=metadata_retriever();
if ( $i % $loopmeta == 0 ) : ?>
You will have to write the metadata_retriever() function and put some error checking around the retrieval of the $loopmeta variable to ensure it comes back as a valid integer (not 0, nor 12.735 for instance :-) )

Wordpress Timeline Show post Monthly

I am fetching data through custom post type and category. I have added 12 category Jan to Dec and Jan has 1 posts Feb have 2 post
What I am struggling to do on January post the 2 circle is showing on the left I want only one January Circle rest of the January post under the circle.
Can you please how can i put check on category?
here is the site http://novartis.portlandvault.com/timeline/
Thanks
<div id="timeline">
<?php
//Define your custom post type name in the arguments
$args = array('post_type' => 'timeline', 'order' => 'asc' );
//Define the loop based on arguments
$loop = new WP_Query( $args );
//Display the contents
while ( $loop->have_posts() ) : $loop->the_post();
$thumb = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'large') );
$category = get_the_terms($id, 'timeline_categories');
?>
<div class="timeline-item">
<div class="timeline-icon">
<div class="timeline-month">
<?php echo $category[0]->name;?>
</div>
</div>
<div class="timeline-content right">
<h2>
<?php the_title(); ?>
</h2>
<p>
<?php echo the_content(); ?>
</p>
<div class="timeline_img">
<img src="<?php echo $thumb; ?>" class="img-responsive">
</div>
</div>
</div>
<?php endwhile;?>
</div>
<!-- Timeline ends here -->
I am not sure using categories is the best way to do this. You are limiting yourself to one years worth of data. I would suggest actually using the post date to separate the posts, then your code could look something like this.
<div id="timeline">
<?php
//Define your custom post type name in the arguments
$args = array('post_type' => 'timeline', 'order' => 'asc' );
//Define the loop based on arguments
$loop = new WP_Query( $args );
//Display the contents
while ( $loop->have_posts() ) : $loop->the_post();
$thumb = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'large') );
$category = get_the_terms($post->ID, 'timeline_categories');
?>
<section id="<?php echo $post->ID; ?>">
<?php
if( $loop->current_post === 0 ) {
$current_quarter = $category[0]->name; ?>
<div class="quarterlyheading">
<?php echo $current_quarter; ?>
<div class="quarterlinebreak"><hr></div>
</div>
<?php } else {
$post_quarter = $category[0]->name;
if($current_quarter != $post_quarter) { ?>
<div class="quarterlyheading">
<?php echo $post_quarter; ?>
<div class="quarterlinebreak"><hr></div>
</div>
<?php }
}
$current_quarter = $post_quarter;
?>
<div class="timeline-item">
<?php
if( $loop->current_post === 0 ) {
$current_month = get_the_time('M'); ?>
<div class="timeline-icon">
<div class="timeline-month">
<?php echo $current_month; ?>
</div>
</div>
<?php } else {
$post_month = get_the_time('M');
if($current_month != $post_month) { ?>
<div class="timeline-icon">
<div class="timeline-month">
<?php echo $post_month; ?>
</div>
</div>
<?php }
}
$current_month = $post_month;
?>
<div class="timeline-content right">
<h2>
<?php the_title(); ?>
</h2>
<p>
<?php echo the_content(); ?>
</p>
<div class="timeline_img">
<img src="<?php echo $thumb; ?>" class="img-responsive">
</div>
</div>
</div>
</section>
<?php endwhile;?>
</div>

CPT output on page breaks other fields

Not sure what i have done wrong here but i noticed that everything dissapears below my code.
If i take fields and put them in top of template then everything works fine.
Code
<?php
$blacklabelpost = array( 'post_type' => 'black-label', );
$loop = new WP_Query( $blacklabelpost );
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php
$images = get_field('photos_of_product'); // get gallery
$image = $images[0]; // get first image in the gallery [1] for second, [2] for third, and so on.
if( $image ) : // only show the image if it exists ?>
<div class="col-sm-3 col-md-4 col-lg-3 product-col">
<a href="<?php the_permalink() ?>">
<img src="<?php echo $image['url']; ?>" class="img-responsive"/>
</a>
<div class="row text-center">
<div class="col-xs-12">
<h3 class="UC sTitle"><?php the_title()?></h3>
<div class="border-line center"></div>
<div class="subtitle about_product_short UC"><?php the_field('about_product_short'); ?></div>
</div>
<div class="col-xs-12">
Läs mer
</div>
</div>
</div>
<?php endif; ?>
<?php endwhile; ?>
Below i just have couple of if get field.
Example
<?php if( get_field('full_width_photo_footer') ): ?>
<div class="F-W sida archive">
<?php
$image = get_field('full_width_photo_footer');
if( !empty($image) ): ?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" class="img-responsive footer-fullwidth-img"/>
<?php endif; ?>
</div>
<?php endif; ?>
As soon as i delete this 'full_width_photo_footer' starts to work again:
<?php
$mypost = array( 'post_type' => 'white-label', );
$loop = new WP_Query( $mypost );
?>
What am i doing wrong ?

Apply Element to Filtered ACF value

I'm trying to place an element (corner ribbon) on certain term images in my archive. I'm using Advanced Custom Fields to assign a value to certain terms. The code below however places a ribbon on EVERY term and not just the one's with the "active15" value associated. Can someone help me with what I'm doing wrong?
This LINK shows a sample of what is happening. Aluminum is the only image that should have the ribbon, but for some reason it seems like the filter isn't being applied.
<!-- Green Ribbon for Top 15 Groups Start -->
<?php
if($terms) {
foreach($terms as $lc) {
if( get_field('group_active_in_focus_15', 'focus15groups_'.$lc->term_id) != 'active15' ) continue;
{
?>
<div class="ribbon ribbon-green">
<div class="banner">
<div class="text">TOP 15</div>
</div>
</div>
<?php } ?>
<?php
}
}
else
{
echo '<div class="ribbon ribbon-blue">
<div class="banner">
<div class="text">TOP 15</div>
</div>
</div>';
}
?>
<!-- Green Ribbon for Top 15 Groups End -->
CODE TO GET/DISPLAY TERMS FOR PAGE
<div class="row">
<?php
if ( get_query_var( 'paged' ) ) {
$paged = get_query_var('paged');
}elseif( get_query_var( 'page' ) ) {
$paged = get_query_var( 'page' );
}else{
$paged = 1;
}
$per_page = 12;
#fix
$term_args = array(
'hide_empty' => 0,
'exclude' => array(16, 20, 22, 25, 27, 28, 30, 4, 33, 264 ), //* Enter ID's of parent categories to exclude from list
);
$number_of_terms = wp_count_terms( 'focus15groups' , $term_args); // This counts the total number terms in the taxonomy with a function)
$paged_offset = ($paged - 1) * $per_page;
$libargs = array(
'orderby' => 'name',
'order' => 'ASC',
'exclude' => array(16, 20, 22, 25, 27, 28, 30, 4, 33, 264 ), //* Enter ID's of parent categories to exclude from list
'number' => $per_page,
'offset' => $paged_offset,
);
$_libargs = wp_parse_args($term_args, $libargs);
$libcats = get_terms( 'focus15groups', $_libargs);
#fix
$i = 0;
foreach($libcats as $lc){
if( $i % 4 == 0 ) { ?>
<div class="clearfix"></div>
<?php }
$i++; ?>
<div class="col-lg-3">
<?php $termlink = get_term_link( $lc->slug, 'focus15groups' ); ?>
<div class="panel panel-default <?php the_field('group_active_in_focus_15', 'focus15groups_'.$lc->term_id); ?>">
<div class="panel-image">
<!-- Green Ribbon for Top 15 Groups Start -->
<?php
if($terms) {
foreach($terms as $lc) {
if( get_field('group_active_in_focus_15', 'focus15groups_'.$lc->term_id) != 'active15' ) continue;
{
?>
<div class="ribbon ribbon-green">
<div class="banner">
<div class="text">TOP 15</div>
</div>
</div>
<?php } ?>
<?php
}
}
else
{
echo '<div class="ribbon ribbon-blue">
<div class="banner">
<div class="text">TOP 15</div>
</div>
</div>';
}
?>
<!-- Green Ribbon for Top 15 Groups End -->
<?php if( get_field('group_active_in_focus_15', 'focus15groups_'.$term->term_id) != 'active15' ) { ?>
<div class="ribbon ribbon-green">
<div class="banner">
<div class="text">TOP 15</div>
</div>
</div>
<?php } else { ?>
<?php } ?>
<div class="thumbnail">
<div class="caption">
<br/><br/>
<h1><span class="label label-info"><?php echo $lc->count ?></span></h1>
<p> Symbols </p>
<h4> <a class="label label-default" href="<?php echo $termlink; ?>"> View Group</a> </h4>
</div>
<!-- Get Image by Attachment ID Start-->
<?php
$attachment_id = get_field('taximage', 'focus15groups_'.$lc->term_id);
if ($attachment_id) {
$image = wp_get_attachment_image_src($attachment_id, 'industrygroup-img');
if ($image) {
?>
<img class="img-responsive" src="<?php echo $image[0]; ?>" />
<?php
}
}
else { ?>
<img class="img-responsive" src="http://www.runningalpha.com/wp-content/uploads/2014/08/RA-logo-300px-groups.jpg" alt="<?php the_title(); ?>" />
<?php } ?>
</div>
<!-- Get Image by Attachment ID End-->
</div>
<div class="panel-footer text-center"><?php echo $lc->name; ?>
</div>
</div>
</div>
<?php } ?>
</div>
I managed to find a fix using the following. By moving my code to the else statement made it show for the correct terms. Something seems odd about that, but it works right!
<?php if( get_field('group_active_in_focus_15', 'focus15groups_'.$lc->term_id) != 'active15' ) { ?>
<?php } else { ?>
<div class="ribbon ribbon-green">
<div class="banner">
<div class="text">TOP 15</div>
</div>
</div>
<?php } ?>

Categories