Display Woocommerce product attributes in a custom single post - php

i have an custom single post and show the product price and product tags and content , now i need show the product attribute in below of content but i test the many code , i can't show in my single post .
i need a code for echothe product attribute in single post .
this is my single.php
<?php get_header(); ?>
<div itemscope itemtype="http://schema.org/Product" id="single">
<div id="similar">
<h2><i class="icon-film"></i>similar product</h2>
<?php
$related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'post_type' => 'product' , 'orderby' => 'rand' , 'numberposts' => 8, 'post__not_in' => array($post->ID) ) );
if( $related ) foreach( $related as $post ) {
setup_postdata($post); ?>
<?php if ( has_post_thumbnail() ) {the_post_thumbnail('first-thumb');} else { ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<img src="<?php bloginfo('template_directory'); ?>/assets/img/no-image.png" alt="<?php the_title(); ?>" /><?php } ?></a>
<?php }
wp_reset_postdata(); ?>
<ul class="product_tags">
<h3><i class=" icon-uniE887"></i>product tag</h3>
<?php woocommerce_product_loop_tags() ?>
</ul>
</div>
<div id="single_body">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div class="h1"><i class="icon-quill"></i><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<h1><span itemprop="name">
<?php the_title(); ?>
</span></h1>
</a>
<ul class="title_icon">
<li title="view"><i class="icon-uniE850"></i><?php if(function_exists('the_views')) { the_views(); } ?></li>
<li title="comment"><i class="icon-bubbles2"></i><?php comments_popup_link('0 ','1 ', '% '); ?></li>
<li title="date"><i class="icon-clock"></i><?php the_time('Y/m/d') ?></li>
</ul>
</div>
<p><?php the_content()?></p>
<?php endwhile;endif; ?>
</div>
<ul class="product_etc">
<h3><i class="icon-uniE02A"></i>detail of productل</h3>
<li itemprop="offers" itemscope itemtype="http://schema.org/Offer"><strong>price</strong>
<div class="price" itemprop="price" ><?php echo $product->get_price_html(); ?></div></li>
<li><strong>category</strong><span><?php echo $product->get_categories( ', ', '' . _n( '', '', sizeof( get_the_terms( $post->ID, '' ) ), '' ) . ' ', '' ); ?></span></li>
<?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
</ul>
<div class="clear"></div>
</div>
<div class="clear"></div>
<div class="comments-page"><?php comments_template(); ?></div>
<?php wp_reset_query(); ?>
<?php get_footer(); ?>
and this is my function.php
<?php
add_filter('show_admin_bar','__return_false');
function the_content_limit($max_char, $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
$content = strip_tags($content,'');
if (strlen($_GET['p']) > 0) {
echo "<p>";
echo $content;
echo "</p>";
}
else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) {
$content = mb_substr($content, 0, $espacio);
$content = $content;
echo "<p>";
echo $content;
echo "...";
echo "</p>";
}
else {
echo "<p>";
echo $content;
echo "</p>";
}
}
//thumbnails
if (function_exists('add_theme_support')) {
add_theme_support('post-thumbnails');
}
//comments
if ( $_GET['post_type'] != 'page' ) {add_post_meta($post_id, 'series', '', true);}
function mytheme_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
extract($args, EXTR_SKIP);
if ( 'div' == $args['style'] ) {
$tag = 'div';
$add_below = 'comment';
} else {
$tag = 'li';
$add_below = 'div-comment';
}
?>
<<?php echo $tag ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ) ?> id="comment-<?php comment_ID() ?>">
<?php if ( 'div' != $args['style'] ) : ?>
<div class="reply">
<?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
</div>
<div id="div-comment-<?php comment_ID() ?>" class="comment-body">
<?php endif; ?>
<div id="comments_data">
<?php printf( __( '<span class="">نظر</span> <cite class="fn">%s</cite>' ), get_comment_author_link() ); ?>
<?php if ( $comment->comment_approved == '0' ) : ?>
<em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></em>
<br />
<?php endif; ?>
<div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>">
<?php
/* translators: 1: date, 2: time */
printf( __('<span class="">در تاریخ: </span><br/> %1$s'), get_comment_date(), get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), ' ', '' );
?>
</div>
</div>
<?php comment_text(); ?>
<!---<div class="comment-author vcard">
<?php if ( $args['avatar_size'] != 0 ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
</div>--->
<?php if ( 'div' != $args['style'] ) : ?>
</div>
<?php endif; ?>
<?php
}
//woocommerce
add_action( 'after_setup_theme', 'woocommerce_support' );
function woocommerce_support() {
add_theme_support( 'woocommerce' );
}
// Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php)
add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' );
function woocommerce_header_add_to_cart_fragment( $fragments ) {
ob_start();
?>
<a class="cart-contents" href="<?php echo WC()->cart->get_cart_url(); ?>"><?php echo sprintf (_n( '%d محصول', '%d محصول', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> به ارزش <?php echo WC()->cart->get_cart_total(); ?></a>
<?php
$fragments['a.cart-contents'] = ob_get_clean();
return $fragments;
}
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_product_loop_tags', 5 );
function woocommerce_product_loop_tags() {
global $post, $product;
$tag_count = sizeof( get_the_terms( $post->ID, 'product_tag' ) );
echo $product->get_tags( ', ', '<span class="tagged_as">' . _n( '', '', $tag_count, 'woocommerce' ) . ' ', '.</span>' );
}
add_action( 'woocommerce_single_product_summary', 'product_attribute_after_price', 15 );
function product_attribute_after_price () {
global $product;
// HERE add your product attribute SLUG or taxonomy
$attribute_slug = 'color';
$taxonomy = strpos($url, 'blog') !== false ? $attribute_slug : 'pa_' . $attribute_slug;
$attribute_name = get_taxonomy( $taxonomy )->labels->singular_name;
$term_name = $product->get_attribute( $taxonomy ); // The value
if( empty($term_name) ) return; // Exit if empty value
// If not empty we display it
$output = '<div class="product-attribute '.$taxonomy.'"><p>';
$output .= '<strong> '.$attribute_name.'</strong>: ';
$output .= '<span> '.$term_name.'</span>';
echo $output . '</p></div>';
}
?>

To display product attributes, you will use this in any hooked function or Woocommerce templates:
// Get an instance of the product object
$_product = wc_get_product( get_the_id() );
if( $_product->has_attributes() ){
// Initializing
$attributes = array();
// Loop through product attributes
foreach( $_product->get_attributes() as $taxonomy => $attribute ){
// The product attribute label name
$attribute_name = get_taxonomy( $taxonomy )->labels->singular_name;
// Set each product attribute with its values in an array
$attributes[] = '<strong>'.$attribute_name.'</strong>: '.$_product->get_attribute($taxonomy);
}
// Display (output)
echo '<div class="product-attributes"><span>'. implode( '</span> <span>', $attributes ) . '</span></div>';
}
Here, get_the_id() can be replaced by a dynamic $product_id variable (which is the post ID of a product custom post type)

Related

change the category from article when the date is expire with wordpress

i have a problem the category does not change
I want to change the category from open to interviewing of an article when the date is expired.
I have added a custom field on my posts called closing_date, when the current date passes the closing date the category changes
this is my code
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php
global $post;
$args = array(
'post_type' => 'openings',
'posts_per_page' => 40,
'meta_key' => 'closing_date',
'orderby' => 'closing_date',
'order' => "DESC",
'tax_query' => array(
'taxonomy' => 'openings_status',
'field' => 'slug',
'terms' => array('open, interviewing, filled'),
),
);
$groupedPosts = get_posts( $args );
foreach($groupedPosts as $post) : setup_postdata($post);
$closing_date = get_field('closing_date');
$Status = get_the_terms($post->ID, 'openings_status' );
//get current date
//convert expire into a date obj
$closing_date = new DateTime($closing_date);
//get current date
$today = new DateTime();
//convert dates to seconds for easier comparison
$closing_date_secs = $closing_date->format('U');
$today_secs = $today->format('U');
if ($closing_date_secs < $today_secs ) :
$Status = 'Interviewing';
//featured set to false
//update_post_meta($post->ID, 'Interviewing', $Status );
// set back to empty
update_post_meta($post->ID, 'closing_date', '' );
?>
<li data-filter="<?php $term = get_the_terms( $post->ID, 'openings_status' ); if ( !empty( $term ) ) { foreach ($term as $t) { echo $t->slug; } } ?>" class="grid-item">
<figure>
<?php if ( has_post_thumbnail() ) : ?><a class="img" href="<?php the_permalink(); ?>"><?php the_post_thumbnail('cp_thumb', array()); ?></a><?php endif; ?>
<figcaption>
<h5 title="<?php the_title(); ?>"><?php the_title(); ?></h5>
<?php if( get_post_meta($post->ID, 'company_name', true) ) { ?><h6><?php if( get_post_meta($post->ID, 'openings_url', true) ) { ?><a target="_blank" href="<?php the_field('openings_url'); ?>"><?php } ?><?php the_field('company_name'); ?><?php if( get_post_meta($post->ID, 'openings_url', true) ) { ?></a><?php } ?></h6><?php } ?>
<?php the_excerpt(); ?>
<p class="more">Learn More</p>
</figcaption>
<ul>
<?php $term = get_the_terms( $post->ID, 'openings_status' );
if ( !empty( $term ) ) { ?>
<li class="status">
<?php foreach ($term as $t) { ?>
<span class="<?php echo $t->slug; ?>"><?php echo $t->name; ?></span>
<?php } ?>
</li>
<?php } ?>
<?php if( get_post_meta($post->ID, 'location', true) ) { ?><li class="location"><?php the_field('location'); ?></li><?php } ?>
<li class="share pdf">
<?php echo do_shortcode('[addtoany]') ?>
</li>
<!-- <?php // if( get_post_meta($post->ID, 'openings_pdf', true) ) { ?> -->
<li class="download-2">
<?php echo do_shortcode('[WORDPRESS_PDF]'); ?>
<p>Download as a PDF
<?php if( function_exists( 'mpdf_pdfbutton' ) ) {
mpdf_pdfbutton( false, 'my link', 'my login text' );
} ?>
</p>
</li>
</ul>
</figure>
</li>
<?php endif;
endforeach;?>

Customizing WordPress Gallery Post Format

My current theme supports Gallery Post Formats. The Gallery format takes all images from the gallery and displays them in a slideshow. I want to be able to add the caption and photo credit line to the bottom of each image as it changes for the information to change along with it.
The current gallery format template looks like this:
<?php if ( has_post_format( 'gallery' ) ) : ?>
<div class="gallery-post-format">
<?php
$galleries = get_post_gallery_images( $post );
$output = '<ul class="gallery-images">';
foreach ($galleries as $gallery) {
$output .= '<li>' . '<img src="'. $gallery . '">' . '</li>';
}
$output .= '</ul>';
echo $output;
?>
</div>
<?php endif; ?>
I am wanting to add the following code to display the captions and photo credit line to each image.
<div>
<?php
$photographer_name = get_post_meta(get_post_thumbnail_id(), 'be_photographer_name', true);
$photographer_url = get_post_meta(get_post_thumbnail_id(), 'be_photographer_url', true);
if ( $photographer_name ) : ?>
<div id="tgg_credit_line" class="tgg-photo-credit" align="right">
📷 Image Credit /
<?php if ( $photographer_url ) : ?>
<a href="<?php echo $photographer_url ?>">
<?php endif; ?>
<?php echo $photographer_name ?>
<?php if ( $photographer_url ) : ?>
</a>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
<div id="tgg_image_caption" class="tgg-image-caption" align="left">
<?php echo get_post(get_post_thumbnail_id())->post_excerpt; ?>
</div>
</div>
How can I do this?
How about this:
<?php if ( has_post_format( 'gallery' ) ) : ?>
<div class="gallery-post-format">
<?php
$gallery = get_post_gallery( $post, false );
$att_ids = wp_parse_id_list( $gallery['ids'] );
$output = '<ul class="gallery-images">';
for ( $i = 0; $i < count( $gallery['src'] ); $i++ ) {
$att_id = $att_ids[ $i ];
$photographer_name = get_post_meta( $att_id, 'be_photographer_name', true );
$photographer_url = get_post_meta( $att_id, 'be_photographer_url', true );
$image = sprintf( '<img src="%s" />',
esc_url( $gallery['src'][ $i ] ) );
$caption = '<div>';
if ( $photographer_name ) {
$caption .= '<div class="tgg-photo-credit" align="right">';
$caption .= '📷 Image Credit /';
if ( $photographer_url ) {
$caption .= sprintf( '%s',
esc_url( $photographer_url ), esc_html( $photographer_name ) );
} else {
$caption .= esc_html( $photographer_name );
}
$caption .= '</div><!-- .tgg-photo-credit -->';
}
$caption .= '</div>';
$excerpt = get_post_field( 'post_excerpt', $att_id );
if ( $excerpt ) {
$caption .= /* wrapped */
'<div class="tgg-image-caption" align="left">' .
$excerpt .
'</div><!-- .tgg-image-caption -->';
}
$output .= '<li>' . $image . $caption . '</li>';
}
$output .= '</ul><!-- .gallery-images -->';
echo $output;
?>
</div><!-- gallery-post-format -->
<?php endif; ?>
Or another version, which directly echoes the output instead of saving it in a variable (i.e. $output):
<?php if ( has_post_format( 'gallery' ) ) : ?>
<div class="gallery-post-format">
<?php
$gallery = get_post_gallery( $post, false );
$att_ids = wp_parse_id_list( $gallery['ids'] );
?>
<ul class="gallery-images">
<?php for ( $i = 0; $i < count( $gallery['src'] ); $i++ ) : ?>
<li>
<?php
$att_id = $att_ids[ $i ];
$photographer_name = get_post_meta( $att_id, 'be_photographer_name', true );
$photographer_url = get_post_meta( $att_id, 'be_photographer_url', true );
$excerpt = get_post_field( 'post_excerpt', $att_id );
?>
<img src="<?php echo esc_url( $gallery['src'][ $i ] ); ?>" />
<div>
<?php if ( $photographer_name ) : ?>
<div class="tgg-photo-credit" align="right">
📷 Image Credit /
<?php if ( $photographer_url ) : ?>
<?php echo esc_html( $photographer_name ); ?>
<?php else : ?>
<?php echo esc_html( $photographer_name ); ?>
<?php endif; // end $photographer_url ?>
</div><!-- .tgg-photo-credit -->
<?php endif; // end $photographer_name ?>
</div>
<?php if ( $excerpt ) : ?>
<div class="tgg-image-caption" align="left">
<?php echo $excerpt; ?>
</div><!-- .tgg-image-caption -->
<?php endif; // end $excerpt ?>
</li>
<?php endfor; // end gallery loop ?>
</ul><!-- .gallery-images -->
</div><!-- .gallery-post-format -->
<?php endif; ?>

WordPress: Display particular category on load with filters

I have a theme with a portfolio that uses filters (ALL, NEW, OLD) to display categories. However, on load, I wish for a particular ("new") category to be the ONLY category displayed.
Then if a user wishes to see past products, they'd click "OLD" and so on..
Please keep in mind that I would create another portfolio and that portfolio's new items would be displayed only on load at first.
I've attempted to find the answer for hours but I have yet to be able to find it.
Here is the code of the portfolio php page:
<?php
/**
* Taxonomy Template for the Portfolios
*/
?>
<?php get_header(); ?>
<?php
if ( $post ) :
$port = wp_get_post_terms( $post->ID, array('portfolios') );
$portfolio = $port[0];
$post_img_width = "";
$post_img_height = "";
global $mav_data; // fetch options stored in $mav_data
$portfolio_order_1 = $mav_data['portfolio_order_1']; // date, title
$portfolio_order_2 = $mav_data['portfolio_order_2']; // ASC, DESC
$tax_query[] = array(
//'taxonomy' => $wp_query->query_vars['taxonomy'],
'taxonomy' => 'portfolios',
'field' => 'slug',
'terms' => array( $portfolio->slug )
);
$args = array(
'post_type'=> 'project',
'posts_per_page'=> -1,
'orderby' => $portfolio_order_1,
'order' => $portfolio_order_2,
'tax_query' => $tax_query
);
$port_query = new WP_Query($args);
?>
<?php
$tag_extra_fields = get_option('portfolios_fields');
$portfolio_layout = $tag_extra_fields[$portfolio->term_id]['_portfolio_layout'];
?>
<section id="content" class="portfolio one-column <?php echo esc_attr( $portfolio_layout ); ?>" role="main">
<div class="wrapper clearfix">
<header class="page-header">
<h1 class="entry-title"><?php echo( $portfolio->name ); ?></h1>
<?php if ($portfolio->description) { ?><p class="portfolio-header-description"><?php echo( $portfolio->description ); ?></p><?php } ?>
<?php
$temp = array();
foreach ( $posts as $post ) {
$temp_args = array();
while ($port_query->have_posts()) : $port_query->the_post(); // the loop begins, we need it here. It's important!!
$temp_cats = wp_get_object_terms( $post->ID, 'project_category'/*, $args*/ );
if ( $temp_cats ) {
foreach ( $temp_cats as $temp_cat ) {
if ( ! in_array( $temp_cat->slug, $temp ) ) {
$temp[] = $temp_cat->slug;
$categories[] = $temp_cat;
}
}
}
endwhile;
}
// DAHEX
$temp = array();
if(!empty($categories)) {
foreach ( $categories as $category ) {
$temp[] = array ('term_id'=>$category->term_id,'name'=>$category->name,'slug'=>$category->slug,'term_group'=>$category->term_group,'term_taxonomy_id'=>$category->term_taxonomy_id,'taxonomy'=>$category->taxonomy,'description'=> $category->description,'parent'=>$category->parent,'count'=> $category->count);
}
}
usort($temp, array(new Sorter('slug'), 'sort')); // Sorting Array by slug
$categories = array();
foreach ( $temp as $category ){
$categories[] =(object) $category;
}
// DAHEX
if(!empty($categories)) {
if(!is_wp_error( $categories )){
echo( '<ul id="filters" class="option-set">
<li>All</li>' );
foreach ( $categories as $category ) {
echo '<li><span class="sep">/</span>' . $category->name . '</li>';
}
echo( '</ul> <!-- /end #filters -->' );
} else {
echo '<span class="ooops">';
_e( 'Ooops! nothing found...', 'mav_framework' );
echo '</span>';
}
}
?>
</header> <!-- /end .page-header -->
<section id="projects">
<?php
while ($port_query->have_posts()) : $port_query->the_post(); // the loop begins
$terms = get_the_terms( get_the_ID(), 'project_category' );
$terms = $terms == false ? array() : $terms;
?>
<?php
$custom = get_post_custom($post->ID);
$portfolio_permalink = $custom["project_permalink"][0];
$portfolio_desc = $custom["project_desc"][0];
if ( !isset( $lightbox_path ) ) {
$lightbox_path = '';
}
// Prepare Project Image Thumb
$project_img = $custom["project_img"][0];
$project_img_ID = $custom['project_img_ID'][0];
// Need some proof check to ensure that no "notice" is thrown ...
if ( ! empty( $portfolio ) ) {
$term_slug = $portfolio->slug;
if ( isset( $custom["lightbox_path"][0] ) ) {
$lightbox_path = $custom["lightbox_path"][0];
} else {
$lightbox_path = '';
}
$empty_thumb = '<img class="portfolios_single_thumb portfolio-image" src="' . get_template_directory_uri() . '/images/thumb.png" width="' . $post_img_width . '" height="' . $post_img_height . '" alt="' . $post->post_title . '" />';
if ( isset( $project_img_ID ) ) {
if ( is_numeric( $project_img_ID ) ) {
$thumb_ID = $project_img_ID;
$thumb = wp_get_attachment_image( $thumb_ID, 'mav-thumbnails', false, array( 'class' => 'portfolios_post_image_thumb portfolio-image', 'alt' => $post->post_title ) );
if ( empty ($thumb) ) {
$thumb = $empty_thumb;
}
} elseif( $project_img_ID != "" ) {
$thumb = '<div class="project_iframe_thumb-$term_slug"><iframe width="' . $post_img_width . '" height="' . $post_img_height . '" src="' . $project_img . '" title="' . $project_img_ID . '" frameborder="0" allowfullscreen></iframe></div>';
} else {
$thumb = $empty_thumb;
}
} else {
$thumb = $empty_thumb;
}
}
?>
<article id="project-<?php the_ID(); ?>" class="element <?php foreach ($terms as $term) { echo strtolower(preg_replace('/\s+/', '-', $term->slug)). ' '; } ?>">
<?php
/**
* Generate the Project Image (Thumb)
*/
if ( $lightbox_path != '' ) { ?>
<figure class="thumb-container">
<a href="<?php echo esc_attr( $lightbox_path ); ?>" data-rel="prettyPhoto" title="<?php the_title_attribute(); ?>">
<span class="overlay lightbox"></span>
<?php mav_framework_project_label( $post, array( 'portfolios-project-label' ) ); ?>
<?php echo( $thumb ); ?>
</a>
</figure> <!-- /end .thumb-container -->
<?php
} elseif ($portfolio_permalink) {
?>
<figure class="thumb-container">
<a target="_blank" href="<?php echo esc_attr( $portfolio_permalink ); ?>" rel="bookmark">
<span class="overlay link"></span>
<?php mav_framework_project_label( $post, array( 'portfolios-project-label' ) ); ?>
<?php echo( $thumb ); ?>
</a>
</figure> <!-- /end .thumb-container -->
<?php } else { ?>
<figure class="thumb-container">
<a href="<?php the_permalink() ?>" rel="bookmark">
<span class="overlay">
<span class="view"><?php _e( 'View', 'mav_framework' ); ?></span>
</span>
<?php mav_framework_project_label( $post, array( 'portfolios-project-label' ) ); ?>
<?php echo( $thumb ); ?>
</a>
</figure> <!-- /end .thumb-container -->
<?php } // end Generate the Project Image (Thumb) ?>
<h2 class="project-title">
<?php if ($portfolio_permalink) { ?>
<a target="_blank" href="<?php echo esc_url( $portfolio_permalink ); ?>" rel="bookmark"><?php the_title(); ?></a>
<?php } else { ?>
<?php the_title(); ?>
<?php } ?>
</h2>
<?php if ($portfolio_desc) { ?><p class="project-description"><?php echo do_shortcode(stripslashes($portfolio_desc)); ?></p><?php } ?>
<footer class="entry-meta">
<span class="posted-on">
<?php _e( '<span class="posted-on-title">Posted on: </span>', 'mav_framework' ); ?><?php /* http://codex.wordpress.org/Formatting_Date_and_Time */ echo get_the_date('F j, Y'); ?>
</span> <!-- /end .posted-on -->
<?php
$project_categories = wp_get_object_terms($post->ID, 'project_category');
if ($project_categories) { ?>
<span class="cat-links">
<?php
_e( '<span class="cat-links-title">Category: </span>', 'mav_framework' );
$project_category = array();
foreach($project_categories as $category) {
$project_category[] = '' . $category->name . '';
}
echo implode(', ', $project_category);
?>
</span> <!-- /end .cat-links -->
<?php } ?>
<?php // Project Tags
$project_tags = wp_get_object_terms($post->ID, 'project_tag');
if ($project_tags) {
$project_tag = array();
foreach($project_tags as $tag) {
$project_tag[] = '' . $tag->name . '';
} ?>
<span class="tag-links">
<?php _e( '<span class="tag-links-title">Tagged: </span>', 'mav_framework' ); ?> <?php echo implode(', ', $project_tag); ?>
</span> <!-- /end .tag-links -->
<?php } ?>
</footer> <!-- /end .entry-meta -->
</article> <!-- /end #project-<?php the_ID(); ?> .element -->
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</section> <!-- /end #projects -->
</div> <!-- /end .wrapper -->
</section> <!-- /end #content -->
<?php endif; ?>
<?php
/**
* Add portfolio bottom quote
*/
if ( $mav_data['portfolio_quote_text'] ) : ?>
<section id="portfolio-quote" class="clearfix">
<div class="wrapper clearfix">
<?php get_template_part( 'inc/block_portfolio_quote' ); ?>
</div> <!-- /end .wrapper -->
</section> <!-- /end #portfolio-quote -->
<?php endif; ?>
<?php get_footer(); ?>
This problem is not related with the Wordpress itself but with the plugin that you, or your theme are using to sort the data.
In this case, it's using Isotope, which is what is filtering the results you see on the page.
By addressing the Isotope's documentation in terms of filtering, we see that the filters can be done through functions or buttons, in this case we're using a combination of both as we want the data to change while clicking but at the same time it already needs to come filtered, as you requested.
So, to solve the problem, it's one line in the isotope's function file:
$container.isotope({
itemSelector : '.element',
filter: '.workshops'
});
I just added the last one.
Apart from this, you just need to hack the code you provided in order to add the "selected" class to the button:
echo( '<ul id="filters" class="option-set">
<li>All</li>' );
foreach ( $categories as $category ) { ?>
<li>
<span class="sep">/</span>
<?php echo $category->name;?>
</li>
<?php
}
echo( '</ul>' );
Now some considerations:
If you change the slug, this will stop working as it's checking for the class "workshops", if you do it, you need to edit the code provided above;
Isotope was masked inside your theme's custom jquery file, which is not a good practice at all, specially for maintenance issues.

Populate Custom Ordering/Sorting woocommerce

I'm trying to figure out on how to populate my custom ordering inside my custom template page.
Here is my work in progress. So far the output shows a select box with empty values. When I check the view source i saw this error.
Warning: Invalid argument supplied for foreach() in C:\Users\Noel\Desktop\xampp\htdocs\lumiere\wp-content\themes\klasik\lumiere-products-page.php on line 23
<?php
$args = array( 'post_type' => 'product', 'posts_per_page' => 10, 'product_cat' => 'Lumiere', 'orderby' => 'rand' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<?php //Woocommerce Custom Ordering ?>
<form class="woocommerce-ordering" method="get">
<select name="orderby" class="orderby">
<?php foreach ( $catalog_orderby_options as $id => $name ) : ?>
<option value="<?php echo esc_attr( $id ); ?>" <?php selected( $orderby, $id ); ?>><?php echo esc_html( $name ); ?></option>
<?php endforeach; ?>
</select>
<?php
// Keep query string vars intact
foreach ( $_GET as $key => $val ) {
if ( 'orderby' === $key || 'submit' === $key ) {
continue;
}
if ( is_array( $val ) ) {
foreach( $val as $innerVal ) {
echo '<input type="hidden" name="' . esc_attr( $key ) . '[]" value="' . esc_attr( $innerVal ) . '" />';
}
} else {
echo '<input type="hidden" name="' . esc_attr( $key ) . '" value="' . esc_attr( $val ) . '" />';
}
}
?>
</form>
<li class="product product-items ">
<div class="product-item">
<?php woocommerce_show_product_sale_flash( $post, $product ); ?>
<div class="product-thumbnail">
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" />'; ?>
</div>
<div class="product-info">
<h3>
<?php the_title(); ?>
</h3>
<h4 class="product-category-title">
<?php
$size = sizeof( get_the_terms( $post->ID, 'product_cat' ) );
echo $product->get_categories( ', ', '<span class="posted_in">' . ' ', '.</span>' );
?>
</h4>
<?php echo $product->get_sku(); ?>
<?php echo apply_filters( 'woocommerce_short_description', $post->post_excerpt ) ?>
<?php if ( $price_html = $product->get_price_html() ) : ?>
<span class="price"><?php echo $price_html; ?></span>
<?php endif; ?>
<div class="product-rating">
<?php if ($average = $product->get_average_rating()) : ?>
<?php echo '<div class="star-rating" title="'.sprintf(__( 'Rated %s out of 5', 'woocommerce' ), $average).'"><span style="width:'.( ( $average / 5 ) * 100 ) . '%"><strong itemprop="ratingValue" class="rating">'.$average.'</strong> '.__( 'out of 5', 'woocommerce' ).'</span></div>'; ?>
<?php endif; ?>
</div>
<?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>
</div>
</div>
</li>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</ul><!--/.products-->

Get Products within Current Product Category

I'm currently playing around with WOOCOMMERCE V2.0.13 and I'm trying to display each product from the current product category (e.g. Construction Products when on the Construction Page), I've managed to display the single products from within the current category but if the product is also in another category (e.g Construction and Enviroment) then the current category breaks and shows zero products either from Construction or Enviroment.
If I could get some advice/help on displaying products from the current category and allow it to work with products that are in multiple categories I'd trully apreciate the help and time.
I'm more than happy to recode this entire section to make it work, here is my code below please let me know if I've missed anything.
Thank you.
<ul class="products">
<?php
global $post, $product;
$categ = $product - > get_categories();
$categ2 = preg_replace('/<a href=\"(.*?)\">(.*?)<\/a>/', "\\2", $categ);
?>
<?php
global $product;
$args = array('post_type' = > 'product', 'posts_per_page' = > '999', 'product_cat' = > $categ2, );
$loop = new WP_Query($args);
while ($loop - > have_posts()): $loop - > the_post();
global $product;
?>
<li>
<a href = "<?php echo get_permalink(); ?>">
<?php
if (has_post_thumbnail()) {
$image = get_the_post_thumbnail($post - > ID, apply_filters('single_product_large_thumbnail_size', 'shop_single'));
$image_title = esc_attr(get_the_title(get_post_thumbnail_id()));
$image_link = get_permalink($product_id);
$attachment_count = count($product - > get_gallery_attachment_ids());
echo apply_filters('woocommerce_single_product_image_html', sprintf('%s', $image_link, $image_title, $image), $post - > ID);
} else {
echo apply_filters('woocommerce_single_product_image_html', sprintf('<img src="%s" alt="Placeholder" />', woocommerce_placeholder_img_src()), $post - > ID);
} ?>
</a>
<div>
<h3>
<?php the_title();?>
<span>
<?php
if ($price_html = $product - > get_price_html()) {
?>
<span class = "price">
<?php echo $price_html; ?>
</span>
<?php } ?>
</span>
</h3>
</div>
<div>
<p>
<?php
$excerpt = get_the_excerpt();
echo string_limit_words($excerpt, 15);
?>
</p>
</div>
</li>
<?php endwhile; ?>
</ul>
<?php if ( have_posts() ) : ?>
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<div class="courses-main">
<ul class="products">
<?php while ( have_posts() ) : the_post(); ?>
<li>
<a href="<?php echo get_permalink(); ?>">
<?php
if ( has_post_thumbnail() ) {
$image = get_the_post_thumbnail( $post->ID, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ) );
$image_title = esc_attr( get_the_title( get_post_thumbnail_id() ) );
$image_link = get_permalink( $product_id );
$attachment_count = count( $product->get_gallery_attachment_ids() );
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '%s', $image_link, $image_title, $image ), $post->ID );
} else {
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '<img src="%s" alt="Placeholder" />', woocommerce_placeholder_img_src() ), $post->ID );
}
?>
</a>
<div>
<h3>
<?php the_title();?>
<span>
<?php if ( $price_html = $product->get_price_html()) { ?>
<span class="price"><?php echo $price_html; ?></span>
<?php } ?>
</span>
</h3>
</div>
<div>
<p>
<?php
$excerpt = get_the_excerpt();
echo string_limit_words($excerpt,15);
?>
</p>
</div>
</li>
<?php endwhile;?>
</ul>
</div>
<?php woocommerce_product_loop_end(); ?>
<?php endif; ?>

Categories