I have a portfolio on a WordPress theme and on the single portfolio page it has a slider of related portfolio items. Well it's a cool feature but it shows the slider even if no related items match that particular portfolio item.
Here is my template where I display the slider:
<div class="related_portfolio">
<?php gbx_related_portfolio($post->ID); ?>
</div>
Here are my functions I am using to create my slider:
function get_related_portfolio($post_id) {
$item_cats = get_the_terms($post_id, 'portfolio_category');
if ($item_cats) {
foreach ($item_cats as $item_cat) $item_array[] = $item_cat->term_id;
}
$args = wp_parse_args($args, array(
'showposts' => 5,
'post__not_in' => array($post_id),
'ignore_sticky_posts' => 0,
'post_type' => 'portfolio',
'tax_query' => array(
array(
'taxonomy' => 'portfolio_category',
'field' => 'id',
'terms' => $item_array
)
),
'orderby' => 'rand'
));
$query = new WP_Query($args);
return $query;
}
AND
function gbx_related_portfolio($post_id) {
?>
<div class="recentportfolio-wrapper">
<div class="image-carousel-header">
<div class="image-carousel-title"><span>Related Items</span></div>
<div class="image-carousel-nav">
<a class="prev"><i class="fa fa-chevron-left"></i></a><a class="next"><i class="fa fa-chevron-right"></i></a>
</div>
<div class="clear"></div>
</div>
<div class="iosslider recentportfolio-carousel <?php echo 'recentportfolio-carousel'.$randomid; ?>">
<ul><?php
$recentPortfolio = get_related_portfolio($post_id);
if ($recentPortfolio->have_posts()) {
while ( $recentPortfolio->have_posts() ) { $recentPortfolio->the_post(); global $post; ?>
<li class="portfolioslider_item">
<div class="portfolio-item">
<div class="image">
<a href="<?php the_permalink(); ?>">
<?php
if('' != get_the_post_thumbnail())
$full_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
else
$full_image = get_template_directory_uri().'/images/thumbnail_placeholder.png';
echo '<img class="size-full" src="' . gbx_process_image($full_image, 270, 240).'" alt="'.get_the_title(get_post_thumbnail_id($post->ID)).'"/>';
?>
</a>
<div class="image-extras">
<div class="image-extras-bg"></div>
<div class="image-extras-content">
<a class="icon" href="<?php the_permalink(); ?>"><span class="glyphicon glyphicon-paperclip"></span></a>
<a class="icon swipebox" href="<?php echo $full_image; ?>" title="<?php echo get_the_title($post->ID); ?>"><span class="glyphicon glyphicon-search"></span></a>
</div>
</div>
</div>
<div class="portfolio-meta">
<div class="post-title"><?php the_title(); ?></div>
<div class="pull-left"><span class="glyphicon glyphicon-time"></span><?php echo get_the_date('F j, Y'); ?></div>
<div class="pull-right">
<span class="likeanimation"></span>
<a href="#" class="like <?php echo gbx_get_like_status($post->ID); ?>" title="<?php echo gbx_get_like_title($post->ID); ?>" data_action="likepost" data_postid="<?php echo $post->ID; ?>" data_nonce="<?php echo wp_create_nonce("gbx_like_nonce"); ?>">
<span class="glyphicon glyphicon-heart"></span>
<span class="likecount"><?php echo gbx_get_likecount($post->ID); ?></span>
</a>
<span class="glyphicon glyphicon-eye-open"></span><?php echo gbx_get_viewcount($post->ID); ?>
</div>
<div class="clear"></div>
</div>
</div>
</li>
<?php } } ?>
</ul>
</div>
</div>
<script>
(function($){
$(window).load(function() {
var $recentportfolio_carousel = $('.<?php echo 'recentportfolio-carousel'.$randomid; ?>');
function custom_recent_portfolio_UpdateSliderHeight(args) {
var height = $('.<?php echo 'recentportfolio-carousel'.$randomid; ?> .portfolioslider_item:eq(' + (args.currentSlideNumber-1) + ')').outerHeight(true);
$recentportfolio_carousel.css({ height: height });
}
$recentportfolio_carousel.iosSlider({
snapToChildren: true,
desktopClickDrag: true,
navPrevSelector: $recentportfolio_carousel.parent().find('a.prev'),
navNextSelector: $recentportfolio_carousel.parent().find('a.next'),
onSliderLoaded: custom_recent_portfolio_UpdateSliderHeight,
onSlideChange: custom_recent_portfolio_UpdateSliderHeight,
onSliderResize: custom_recent_portfolio_UpdateSliderHeight
});
});
})(jQuery);
</script>
<?php
}
Your code is quite mingled with a lot of syntax errors. I have put all your code in one function and rearrange it and fixed the errors. I'm not 100% sure about this part though, it is untested
function gbx_related_portfolio() {
wp_reset_postdata();
global $post;
$orig_post = $post;
if ( 'portfolio' == get_post_type() ) {
$tags = wp_get_post_terms($post->ID, 'portfolio_category');
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
'tax_query' => array(
array(
'taxonomy' => 'portfolio_category',
'terms' => $tag_ids,
'operator' => 'IN'
)
),
'post__not_in' => array( $post->ID ),
'posts_per_page' => 5,
'ignore_sticky_posts' => 0
);
$my_query = new wp_query( $args );
if( $my_query->have_posts() ) { ?>
<div class="recentportfolio-wrapper">
<div class="image-carousel-header">
<div class="image-carousel-title"><span>Related Items</span></div>
<div class="image-carousel-nav">
<a class="prev"><i class="fa fa-chevron-left"></i></a><a class="next"><i class="fa fa-chevron-right"></i></a>
</div>
<div class="clear"></div>
</div>
<div class="iosslider recentportfolio-carousel <?php echo 'recentportfolio-carousel'.$randomid; ?>">
<ul>
<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
<li class="portfolioslider_item">
<div class="portfolio-item">
<div class="image">
<a href="<?php the_permalink(); ?>">
<?php
if('' != get_the_post_thumbnail())
$full_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
else
$full_image = get_template_directory_uri().'/images/thumbnail_placeholder.png';
?>
</a>
<div class="image-extras">
<div class="image-extras-bg"></div>
<div class="image-extras-content">
<a class="icon" href="<?php the_permalink(); ?>"><span class="glyphicon glyphicon-paperclip"></span></a>
<a class="icon swipebox" href="<?php echo $full_image; ?>" title="<?php echo get_the_title($post->ID); ?>"><span class="glyphicon glyphicon-search"></span></a>
</div>
</div>
</div>
<div class="portfolio-meta">
<div class="post-title"><?php the_title(); ?></div>
<div class="pull-left"><span class="glyphicon glyphicon-time"></span><?php echo get_the_date('F j, Y'); ?></div>
<div class="pull-right">
<span class="likeanimation"></span>
<a href="#" class="like <?php echo gbx_get_like_status($post->ID); ?>" title="<?php echo gbx_get_like_title($post->ID); ?>" data_action="likepost" data_postid="<?php echo $post->ID; ?>" data_nonce="<?php echo wp_create_nonce("gbx_like_nonce"); ?>">
<span class="glyphicon glyphicon-heart"></span>
<span class="likecount"><?php echo gbx_get_likecount($post->ID); ?></span>
</a>
<span class="glyphicon glyphicon-eye-open"></span><?php echo gbx_get_viewcount($post->ID); ?>
</div>
<div class="clear"></div>
</div>
</div>
</li>
<?php endwhile; ?>
</ul>
</div>
</div>
<script>
(function($){
$(window).load(function() {
var $recentportfolio_carousel = $('.<?php echo 'recentportfolio-carousel'.$randomid; ?>');
function custom_recent_portfolio_UpdateSliderHeight(args) {
var height = $('.<?php echo 'recentportfolio-carousel'.$randomid; ?> .portfolioslider_item:eq(' + (args.currentSlideNumber-1) + ')').outerHeight(true);
$recentportfolio_carousel.css({ height: height });
}
$recentportfolio_carousel.iosSlider({
snapToChildren: true,
desktopClickDrag: true,
navPrevSelector: $recentportfolio_carousel.parent().find('a.prev'),
navNextSelector: $recentportfolio_carousel.parent().find('a.next'),
onSliderLoaded: custom_recent_portfolio_UpdateSliderHeight,
onSlideChange: custom_recent_portfolio_UpdateSliderHeight,
onSliderResize: custom_recent_portfolio_UpdateSliderHeight
});
});
})(jQuery);
</script>
<?php
}
}
}
$post = $orig_post;
wp_reset_query();
}
Just call it as follows
<div class="related_portfolio">
<?php gbx_related_portfolio(); ?>
</div>
Related
I have some problems with conditional (if/else) at Wordpress function.
I need to hide this <span class="xs-item-count highlight xscart"><?php echo esc_html($xs_product_count); ?></span> if the value $xs_product_count is 0 on a cart.
What should I do?
I've tried using PHP Native, but My Website has an error.
My belonging code is:
<a href="<?php echo esc_url( wc_get_cart_url() ); ?>" class ="mobile-cart-notif offset-cart-menu">
<span class="xs-item-count highlight xscart">
<?php echo esc_html($xs_product_count); ?>
</span>
<i class="icon icon-bag"></i>
</a>
I would try this:
<a href="<?php echo esc_url( wc_get_cart_url() ); ?>" class="mobile-cart-notif offset-cart-menu">
<?php if ((int) $xs_product_count > 0) : ?>
<span class="xs-item-count highlight xscart">
<?php echo esc_html($xs_product_count); ?>
</span>
<?php endif; ?>
<i class="icon icon-bag"></i>
</a>
Putting the (int) in front of the $xs_product_count in the if statement is called "casting" a variable to a type, and it'll change the string of '0' to integer 0 which lets us reliably compare with the > operator.
<a href="<?php echo esc_url( wc_get_cart_url() ); ?>" class ="mobile-cart-notif offset-cart-menu">
<?php if (0 < $xs_product_count) {?>
<span class="xs-item-count highlight xscart">
<?php echo esc_html($xs_product_count); ?>
</span>
<?php } ?>
<i class="icon icon-bag"></i>
</a>
You can use below condition before span tag.
<a href="<?php echo esc_url( wc_get_cart_url() ); ?>" class ="mobile-cart-notif offset-cart-menu">
<?php
if($xs_product_count != 0 ){
?>
<span class="xs-item-count highlight xscart">
<?php echo esc_html($xs_product_count); ?>
</span>
<?php } ?>
<i class="icon icon-bag"></i>
</a>
Or you can hide complete section by below code.
<?php
if($xs_product_count != 0 ){
?>
<a href="<?php echo esc_url( wc_get_cart_url() ); ?>" class ="mobile-cart-notif offset-cart-menu">
<span class="xs-item-count highlight xscart">
<?php echo esc_html($xs_product_count); ?>
</span>
<i class="icon icon-bag"></i>
</a>
<?php } ?>
I use the rethink theme in wordpress, and use the wp-paginate plugin
in arcive.php, category.php and index.php pagination is fine
but why in page.php not running?
and I created my own template showing all the posts
posting.php
<?php
/*
Template Name: posting
*/
get_header();
?>
<div class="full-content">
<div class="grid_17 alpha">
<div class="content_bar">
<div class="feature_content">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$count_posts = wp_count_posts();
$published_posts = $count_posts->publish;
$myposts = get_posts(array('posts_per_page'=>3)); ;
foreach($myposts as $post) :
setup_postdata($post);
?>
<div id="post-<?php the_ID(); ?>" <?php post_class('product'); ?>>
<div class="post-info">
<h1 class="product_title">
<a href= "<?php the_permalink(); ?>" rel="bookmark" title="<?php echo sprintf(__("Permanent link to %s", 'rethink'), get_the_title(get_the_ID())); ?>">
<?php the_title(); ?>
</a>
</h1>
<div class="detail">
<ul class="post_meta">
<li class="admin"><?php printf(__("Posted by %s", 'rethink'), get_the_author_link()); ?></li>
<li class="date"><?php printf(__('Posted on %s', 'rethink'), get_the_time('F j, Y')); ?></li>
<li class="category"><?php the_category(','); ?></li>
<li class="commentt"><?php comments_popup_link(__('No Comments.', 'rethink'), __('1 Comment.', 'rethink'), __('% Comments.', 'rethink')); ?></li>
</ul>
</div>
</div>
<div class="post_thumbnail_wrapper">
<?php if (has_post_thumbnail()) { ?>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('post_thumbnail', array('class' => 'postimg')); ?>
</a>
<?php
} else {
echo rethink_main_image();
}
?>
</div>
<div class="product_content"><?php the_excerpt(); ?><div class="buttons"><a class="btn-2" href="<?php the_permalink() ?>"><span><?php _e('Read Review', 'rethink') ?></span></a></div>
</div>
</div>
<?php endforeach;
if(function_exists('wp_paginate')){
wp_paginate(); }
wp_reset_postdata(); ?>
<div class="clear"></div>
<?php endwhile;
else:
?>
<div class="product">
<p>
<?php _e('Sorry, no posts matched your criteria.', 'rethink'); ?>
</p>
</div>
<?php endif; ?>
</div>
</div>
</div>
<div class="grid_7 omega">
<!--Start Sidebar-->
<?php get_sidebar(); ?>
<!--End Sidebar-->
</div>
</div>
<?php get_footer(); ?>
how i want to display the pagination of my coding ????
sorry if the line of code is not neat I still newbie
Update this Code:
if(function_exists('wp_paginate')){
wp_paginate();
}
to this code:
if(function_exists('wp_paginate')){
wp_paginate(array('page' => 'page'));
}
I have a 4.3 wordpress system that i install on it the "Orca Theme".
I notice i have duplicate indication of Post View Count:
I want to remove the First Indicator.
I try to look around amd search in the theme code and didnt find what display the First indicator.
postformat/standart.php:
<?php
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_get_attachment_image_src($thumb_id, 'postlist', true);
$title_meta = get_post_meta($post->ID, 'title_style', true);
$title_meta = ($title_meta == ('banner' || 'title')) ? $title_meta : "standard";
$category = get_the_category();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> class="post standard">
<?php if($title_meta == "banner"){ ?>
<a class="basicfeature" href="<?php esc_url(the_permalink()); ?>" style="background-image:url('<?php echo esc_url($thumb_url[0]); ?>');"></a>
<h1><?php the_title(); ?></h1>
<?php }elseif($title_meta == "feature"){ ?>
<a href="<?php esc_url(the_permalink()); ?>" class="largeimage postfeature" style="background-image:url('<?php echo esc_url($thumb_url[0]); ?>');">
<div class="shadow"></div>
<h1><?php the_title(); ?></h1>
</a>
<?php }else{ ?>
<h1><?php the_title(); ?></h1>
<?php } ?>
<div class="info">
<div class="left">
<i class="issticky fa fa-thumb-tack "></i><img src="http://0.gravatar.com/avatar/<?php echo esc_attr(md5(get_the_author_meta('user_email'))); ?>?s=32" alt="author" class="minigravatar"><?php the_author(); ?>
</div>
<div class="right">
<i class="fa fa-clock-o"></i><?php echo esc_html(orca_get_time()); ?>
<div class="category"><i class="fa fa-tags"></i>
<?php if($category){
echo '' . $category[0]->name.' ';
} ?>
</div>
</div>
</div>
<div class="postcontents">
<?php the_content('', FALSE, ''); ?>
</div>
<div class="footer">
<?php esc_html_e('Read More', 'orcawp'); ?>
<i class="fa fa-comments"></i><?php echo esc_html(get_comments_number($post->id)); ?>
<?php if(get_post_meta($post->ID, '_count-views_all', true) != ''){ ?>
<i class="fa fa-bullseye"></i><?php echo esc_html(get_post_meta($post->ID, '_count-views_all', true)); ?>
<?php } ?>
</div>
Solve it!
I just Deactivated the "BAW Post Views Count" plugin and now it removed!
i want to add a css class to taxonomy active link in my sidebar, i have this code..
function list_posts_by_taxonomy( $post_type, $taxonomy, $get_terms_args = array(), $wp_query_args = array() ){
$tax_terms = get_terms( $taxonomy, $get_terms_args );
if( $tax_terms ){
foreach( $tax_terms as $tax_term ){
$query_args = array(
'post_type' => $post_type,
"$taxonomy" => $tax_term->slug,
'post_status' => 'publish',
'posts_per_page' => -1,
'ignore_sticky_posts' => true
);
$query_args = wp_parse_args( $wp_query_args, $query_args );
$my_query = new WP_Query( $query_args );
if( $my_query->have_posts() ) { ?>
<div id="panel-project">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel">
<div class="panel-heading" role="tab" id="heading<?php echo $tax_term->slug; ?>">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse<?php echo $tax_term->slug; ?>" aria-expanded="true" aria-controls="collapse<?php echo $tax_term->slug; ?>">
<?php echo $tax_term->name; ?>
</a>
</h4>
</div>
<div id="collapse<?php echo $tax_term->slug; ?>" class="panel-collapse collapse<?php if ( is_singular('csis_project') ) { ?> in<?php } ?>" role="tabpanel" aria-labelledby="heading<?php echo $tax_term->slug; ?>">
<div class="panel-body">
<ul>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>
</div>
</div>
</div>
</div>
</div>
<?php } wp_reset_query();
}
}
}
and it look like this
i want the the link in active page with different color such as red,
how can i do that.. thx guys
never mind, ive got my own solution here.., Thanks for the comment btw
<?php $IDOutsideLoop = $wp_query->post->ID; global $post; ?>
<?php
$taxonomyname = 'csis_project_category';
$taxonomyterms = get_terms($taxonomyname, 'hide_empty=0&hierarchical=0&order=DESC');
foreach ($taxonomyterms as $taxonomyterm) {
$args=array(
'post_type' => 'csis_project',
$taxonomyname => $taxonomyterm->name,
'post_status' => 'publish',
'order' => 'DESC',
'posts_per_page' => -1,
'caller_get_posts'=> 1,
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) { ?>
<div id="panel-project">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel">
<div class="panel-heading" role="tab" id="heading<?php echo $taxonomyterm->slug; ?>">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapse<?php echo $taxonomyterm->slug; ?>" aria-expanded="true" aria-controls="collapse<?php echo $taxonomyterm->slug; ?>">
<?php echo $taxonomyterm->name; ?>
</a>
</h4>
</div>
<div id="collapse<?php echo $taxonomyterm->slug; ?>" class="panel-collapse collapse<?php if ( is_singular('csis_project') ) { ?> in<?php } ?>" role="tabpanel" aria-labelledby="heading<?php echo $taxonomyterm->slug; ?>">
<div class="panel-body">
<ul>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li <?php if(is_singular( 'csis_project' ) && $IDOutsideLoop == $post->ID) { echo " class='current'"; } ?>><?php the_title(); ?></li>
<?php endwhile; ?>
</ul>
</div>
</div>
</div>
</div>
</div>
<?php } wp_reset_postdata(); } ?>
Right now I'm learning Opencart, and I'm trying to make my latest product display with jCarousel. I'm using Opencart 1.5.4.
This is what I've already tried, but still failed: http://www.packtpub.com/article/opencart-themes-using-jCarousel-plugin
I'm editing the latest.tpl file step-by-step as in the tutorial, but I'm getting stuck on the eight step.
When I open Firefox and hit refresh nothing happens, no error or message. This is my latest.tpl file:
<script type="text/javascript" src="catalog/view/javascript/jquery/jCarousel/js/jquery.jcarousel.min.js"></script>
<link rel="stylesheet" type="text/css" href="catalog/view/javascript/jquery/jCarousel/skins/tango/skin.css" />
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#latestcarousel').jcarouseljcarousel();
});
</script>
<div class="box">
<div class="box-heading"><?php echo $heading_title; ?></div>
<div class="box-content">
<div id="latestcarousel" class="box-product">
<?php foreach ($products as $product) { ?>
<div class="jCarousel-skin-tango">
<?php if ($product['thumb']) { ?>
<div class="image"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" /></div>
<?php } ?>
<div class="name"><?php echo $product['name']; ?></div>
<?php if ($product['price']) { ?>
<div class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price']; ?>
<?php } else { ?>
<span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span>
<?php } ?>
</div>
<?php } ?>
<?php if ($product['rating']) { ?>
<div class="rating"><img src="catalog/view/theme/default/image/stars-<?php echo $product['rating']; ?>.png" alt="<?php echo $product['reviews']; ?>" /></div>
<?php } ?>
<div class="cart"><input type="button" value="<?php echo $button_cart; ?>" onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button" /></div>
</div>
<?php } ?>
</div>
</div>
</div>
Any suggestion?
This is what I do with latest.tpl file. It works now.
<link rel="stylesheet" type="text/css" href="catalog/view/javascript/jquery/jCarousel/skins/tango/skin.css" />
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#latestcarousel').jcarousel({
scroll: 1,
visible: 3,
auto: 3,
rtl: true,
wrap: 'circular'
});
});
</script>
<div class="box">
<div class="box-heading"><?php echo $heading_title; ?></div>
<div class="box-content">
<div class="box-product">
<ul id="latestcarousel" class="jcarousel-skin-tango">
<?php foreach ($products as $product) { ?>
<li class="carousel-latest">
<div class="image"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" /></div>
<div class="name"><?php echo $product['name']; ?></div>
<?php if ($product['price']) { ?>
<div class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price']; ?>
<?php } else { ?>
<span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span>
<?php } ?>
</div>
<?php } ?>
</li>
<?php } ?>
</ul>
</div>
</div>
</div>
Thanks for anything.