I’d like to be able to display the category description for each of the categories in our shop – both parent and child – either in an overlay below the h4 category title or underneath.
Our theme has a filter which governs this layout, and any attempts I’ve made to adapt it and add an additional div or span by including echo category_description() inside the h4 title tags has been unsuccessful - [https://www.epianos.co.uk/digital-pianos/][1]
<div class="category-grid-item">
<a class="category-img" href="<?php echo esc_url( get_term_link( $c->slug, 'product_cat' ) ); ?>">
<?php
$thumbnail_id = get_term_meta( $c->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_image_src( $thumbnail_id, 'large' );
$image = isset( $image[0] ) ? $image[0] : wc_placeholder_img_src();
if ( isset( $image ) ) {
?>
<img src="<?php echo esc_url( $image ); ?>" alt="<?php echo esc_attr( $c->name ); ?>" />
<?php
}
?>
</a>
<h4 class="category-title">
<?php echo esc_html( $c->name ); ?><span class="count"><?php echo esc_attr( $c->count ); ?></span>
</h4>
</div>
[1]: https://www.epianos.co.uk/digital-pianos/
Try to pass the category id to the category_description function
from documentation:
category_description( int $category )
Retrieves category description.
$category (int) (Optional) Category ID. Defaults to the current category ID.
Your code should be as follows:
<h4 class="category-title">
<?php echo esc_html( $c->name ); ?> <?php echo category_description( $c->term_id ); ?>
<span class="count"><?php echo esc_attr( $c->count ); ?></span>
</h4>
Related
I have acf option page with the field Relationship. I display this block on many pages of the site. How can I exclude the current page from the list of displayed pages?
My code for Relationship:
<?php $coin_pages = get_field('sb_sector_pages_pages', 'option');
if( $coin_pages ):
foreach( $coin_pages as $post ) :
$permalink = get_permalink( $post->ID );
$thumbnail = get_the_post_thumbnail( $post->ID, 'full');
$title = get_the_title( $post->ID );
setup_postdata($post); ?>
<li class="coin-article__sidebar-list-item">
<a href="<?php echo esc_html( $permalink ); ?>" class="coin-article__sidebar-list-link">
<div class="coin-article__sidebar-coin-ico">
<?php echo $thumbnail; ?>
</div>
<span class="coin-article__sidebar-coin-title"><?php echo esc_html( $title ); ?></span>
</a>
</li>
<?php endforeach; ?>
I tried to add this to my functions.php but it doesn’t work for me:
add_filter('acf/fields/relationship/query/name=sb_sector_pages_pages', 'exclude_id', 10, 3);
function exclude_id ( $args, $field, $post ) {
$args['post__not_in'] = array( $post );
return $args;
}
How to exclude a current page from the ACF relationship query??
I am trying to get the image from a category but I cannot retrieve the image.
Today I already learned that I had to use
get_field('product', $term->taxonomy . '_' . $term->term_id);
to fetch content.
But when I use this same method to fetch an image URL from an ACF Field linked to my custom post type category, I do not recieve any values.
This is my code (the var_dump is included):
<?php
$args = array(
'post_type' => 'segments-overview',
'orderby' => 'date', // we will sort posts by date
);
$query = new WP_Query( $args );
$all_terms = [];
if( $query->have_posts() ) :
while( $query->have_posts() ): $query->the_post();
$terms = get_the_terms(get_the_ID(), 'category-segments-overview');
foreach($terms as $term) $all_terms[$term->term_id] = $term;
endwhile;
foreach($terms as $term):
?>
<div class="segments-card">
<div class="img">
<?php
$image = get_field('image', $term->taxonomy . '_' . $term->term_id);
if( !empty( $image ) ): ?>
<img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
<?php endif; ?>
</div>
<div class="content">
<div class="title"><?php echo $term->name; ?></div>
<!-- <?php print_r($term); ?> -->
<a class="button transparent" href="/segments/<?php echo $term->slug; ?>">
<?php echo __('View All','axia'); ?>
</a>
</div>
</div>
</div>
<?php endforeach;
wp_reset_postdata();
else :
?>
<div class="no-posts-found">
<h2>There were no items found</h2>
<h3>Please try a different search</h3>
</div>
<?php
endif;
?>
I use this var_dump to see if everything is fetched:
$image = get_field('image', $term->taxonomy . '_' . $term->term_id);
echo '<pre>';
echo "Image field value:";
var_dump($image);
echo "Category field value:";
var_dump($term);
echo '</pre>';
The only thing is that I do not get the value from my image in my category that is made in ACF.
You can simply get value by passing term object as second parameters.
$image = get_field('image', $term);
Check the docs here: https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/
So we all know that in wordpress woocommerce, there is a product detail tab and review tab in the Single Product page.
I am trying to change the content/comment in the review tab to 70% and have a widget next to the comment. But I don't see to be able to do it. My review form is using WP Advanced comment plugin. https://wordpress.org/plugins/wp-advance-comment/
It can be changed in the woocommerce/single-product/tabs/tabs.php
<div class="wc_reviewbox">
<div class="woocommerce-tabs wc-tabs-wrapper">
<ul class="tabs wc-tabs" role="tablist">
<?php foreach ( $tabs as $key => $tab ) : ?>
<li class="<?php echo esc_attr( $key ); ?>_tab" id="tab-title-<?php echo esc_attr( $key ); ?>" role="tab" aria-controls="tab-<?php echo esc_attr( $key ); ?>">
<?php echo apply_filters( 'woocommerce_product_' . $key . '_tab_title', esc_html( $tab['title'] ), $key ); ?>
</li>
<?php endforeach; ?>
</ul>
<?php foreach ( $tabs as $key => $tab ) :
echo print_r($tab);
?>
<div class="woocommerce-Tabs-panel woocommerce-Tabs-panel--<?php echo esc_attr( $key ); ?> panel entry-content wc-tab" id="tab-<?php echo esc_attr( $key ); ?>" role="tabpanel" aria-labelledby="tab-title-<?php echo esc_attr( $key ); ?>">
<?php call_user_func( $tab['callback'], $key, $tab ); ?>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="wc_adbox">
[PUT WIDGET CODE HERE]
</div>
Do some css manipulation.
.wc_reviewbox {
width:72%;float:left;
}
.wc_adbox {
width:25%;float:right;
}
I'm trying to integrate the Simple Lightbox plugin into Advanced Custom Fields image fields.
Basically I want any images on a page (populated via acf image fields) to open in the lightbox when clicked, and also be grouped together with all other images within the lightbox so they can be navigated through like a slideshow. This is built-in functionality for the Simple Lightbox plugin, but I don't know how to integrate it with my template code for image fields.
For acf WYSIWYG fields I'm using this...
<?php
$content = get_field('wysiwyg');
if ( function_exists('slb_activate') )
$content = slb_activate($content);
echo $content;
?>
...which works great, but adapting that to image fields is eluding me.
Here's my template code for image fields (without any attempts at integrating Simple Lightbox):
<?php
$image = get_field( 'img' );
if( ! empty( $image ) ) {
$url = $image['url'];
$alt = $image['alt'];
$caption = $image['caption'];
$size = 'large';
$thumb = $image['sizes'][ $size ];
$width = $image['sizes'][ $size . '-width' ];
?>
<?php if( $caption ): ?>
<div class="wp-caption" style="width: <?php echo $width; ?>px">
<?php endif; ?>
<a href="<?php echo $url; ?>">
<img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" />
</a>
<?php if( $caption ): ?>
<p class="wp-caption-text"><?php echo $caption; ?></p>
</div>
<?php endif; ?>
<?php } ?>
Any suggestions for how to integrate Simple Lightbox into this? Thanks in advance!
Use php output buffering to store your template in a variable. Put ob_start() at the top, then at the bottom ob_get_clean() will stop the output buffering, and you can save the return value to a variable. Then pass that to slb_activate.
<?php
ob_start();
$image = get_field( 'img' );
if( ! empty( $image ) ) {
$url = $image['url'];
$alt = $image['alt'];
$caption = $image['caption'];
$size = 'large';
$thumb = $image['sizes'][ $size ];
$width = $image['sizes'][ $size . '-width' ];
?>
<?php if( $caption ): ?>
<div class="wp-caption" style="width: <?php echo $width; ?>px">
<?php endif; ?>
<a href="<?php echo $url; ?>">
<img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" />
</a>
<?php if( $caption ): ?>
<p class="wp-caption-text"><?php echo $caption; ?></p>
</div>
<?php endif; ?>
<?php } ?>
<?php $content = ob_get_clean(); ?>
<?php echo slb_activate($content); ?>
I want to make a query for post added with a different Post Type:
The original query was like this:
query_posts( "post_type=market-item&posts_per_page=".$post_per_page."&paged=".$paged );
I don't know where or how to specify the logic that only show one category or two categories for custom post type
Here is part of the code:
<ul class="item-list list">
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$post_per_page=16;
//query_posts( "post_type=market-item&posts_per_page=".$post_per_page."&paged=".$paged );
//query_posts('post_type=market-item', );
$args = array('post_type' => 'market-item','cat'=>13);
query_posts($args );
if(have_posts()) :while ( have_posts() ) : the_post();
$image1= get_post_meta( $post->ID, 'sangvish_Image1', true );
$image2= get_post_meta( $post->ID, 'sangvish_Image2', true );
$terms_as_text = strip_tags( get_the_term_list( $wp_query->post->ID, 'item-cat', '', ' / ', '' ) );
?>
<li class="index-page-thumbnail">
<div class="thumbnail">
<a href="<?php the_permalink(); ?>">
<img src="<?php echo $image1; ?>"
border="0"
alt="<?php the_title(); ?>"
title="<?php the_title(); ?>"
height="80"
width="80"
class="thumbnail-image-popup preload no_preview"
image-preview-width=""
image-preview-height=""
data-item-name="<?php the_title(); ?>"
data-item-author="<?php the_author(); ?>"
data-item-category="<?php echo $terms_as_text; ?>"
data-item-cost="<sup><?php echo sangvish_currency_simb(); ?></sup><?php echo get_post_meta( $post->ID, 'sangvish_price', true ); ?>"
popup-large="<?php echo $image2; ?>" />
</a>
</div>
Try below code
$cnt = 1;
$categories = get_the_category();
$separator = ' | ';
$output = '';
if($categories){
foreach($categories as $category) {
if($cnt<=2) {
$output .= ''.$category->cat_name.''.$separator;
}
$cnt++;
}
echo trim($output, $separator);
}