I added a custom taxonomy called "Topics" to woocomerce products and Now i would like to add an image to each Topic and have it shown on the page of that Topic.
I am trying to use Advanced Custom fields plugin but I do not know where to the the ACF php code.
Any help would be greatly appreciated.
Advanced Custom Fields Example Link Here https://www.advancedcustomfields.com/resources/code-examples/
get the ACF image filed in Taxonomy
<?php
$products_category_object = get_queried_object();
$product_category_taxonomy = $products_category_object->taxonomy;
$product_category_term_id = $products_category_object->term_id;
$category_acf_image = get_field('your ACF Image Field name', $product_category_taxonomy.'_'.$product_category_term_id);
echo "<pre>";
print_r($category_acf_image);
echo "</pre>";
?>
<img src="<?php echo $category_acf_image['your url key']; ?>" />
There is a plugin Custom Category Image available in wordpress to do that.
This plugin will add option to add image file for each category/taxonomy.
As specified in the plugin description use following code to get the image anywhere in your code -
MGC_Custom_Category_Image::get_category_image($term_id, $size);
Related
I'm trying to learn WordPress and developing custom plugins. I'm trying to make a custom plugin where it will display just the Product Image from the Woocommerce plugin to the page. I have 1 product, and I've been reading documentation and haven't really found anything that explains it clearly or works. This is all I have now
<?php
$gallery_shortcode = '[gallery id="' .intval($post->$post_parent).'"]';
print apply_filters('the_content', $gallery_shortcode);
?>
Honestly the question is not very clear, so I'll try to guess what you're looking for.
You can "get" a product image with this function:
woocommerce_get_product_thumbnail();
If you need it in a custom single product PHP template, simply:
echo woocommerce_get_product_thumbnail();
If you need it in a shortcode inside the single product page:
add_shortcode( 'product_image', 'bbloomer_product_image_shortcode' );
function bbloomer_product_reviews_shortcode() {
return woocommerce_get_product_thumbnail();
}
...and then use [product_image] shortcode to show the image
I am trying to display Advanced Custom Field on my WooCommerce storefront in html list tag. I modified the file:
content-product_cat.php
from this:
<li <?php wc_product_cat_class( '', $category ); ?>>
to this:
<li style="background: <?php the_field('my_ACF_field'); ?>" <?php wc_product_cat_class( '', $category ); ?>>
And also I added ACF field on my WP backend and assigned it to my page called "Store" which is the WooCommerce storefront. I can fill the input on my backend (Store page) but it's not showing on storefront/category page, it's just not passing. Where is the problem?
I also tried to set this field as taxonomy, and display it on category setting in WooCommerce, also without success.
I think you'll need to use the second parameter on ACF the_field, to get the value for the specific object that you're after. E.g. if you have the ACF Field set on a product category, you'll need to pass in the term that you're currently looking at to get the right value.
I believe that on a category page you'll need to use something like
<li style="background: <?php the_field('my_ACF_field', $category);?>" <?php wc_product_cat_class( '', $category ); ?>>
This ACF documentation field gives more detail about adding fields to taxonomy terms: https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/
I have created a custom post type called:'activities' and created a taxonomy for it called: 'activity_locations'. I have then added a custom field to the taxonomy for an image using Advanced Custom Fields, this image field is called: 'activity_location_image'
On the single template I have managed to display the taxonomy for the product with the following code:
Available in: <?php the_terms( $post->ID, 'activity_locations', ' ', ' / ' ); ?>
However I need to elaborate on this to add a small image after the taxonomy text. I have tried the following code but it hasn’t worked (nothing is displaying):
<?php
$term = get_field('test');
if( $term ): ?>
<img src="<?php echo get_field('activity_location_image', $term); ?>" />
<?php endif; ?>
Can anyone offer any advice/assistance on how to make this work?
If you are still on the single template page, then get_field() without a second argument will only be fetching metadata for your current post object, not the related term objects.
If you read the documentation for get_field() you'll see that to query for term fields you need to use the format
get_field('field_name', 'taxonomyname_X)
Where taxonomyname would be activity_locations and X would be the term ID.
Since you want to customize the display and use the data about the terms, you'll have to swap the_terms() with wp_get_post_terms() which will give you an array of term objects. You can then loop over the array, grabbing the image for each term and outputting the HTML to display the term.
I'm having trouble showing ACF on a custom taxonomy page.
The custom tax is 'destinations' with the page being taxomony-destinations.php the field is called 'destination_landing_image. I'm trying to display it on 'mysite.com/destinations/coutryname' as follows:
<?php if (have_posts()) : while (have_posts()) : the_post();
$destination_landing_image = get_field('destination_landing_image');
<img src="<?php echo $destination_landing_image['url'] ?>" alt="<?php echo $destination_landing_image['alt'] ?>">
<?php endwhile; endif; ?>
Oddly enough the page in question does show up the ACF fields within the custom post type(holidays) which is lower in the page. So I guess firstly am I calling it correctly within the loop? and Secondly is a custom taxonomy the right type of page to use?
When you use ACF with posts you can just use get_field() as you are, but when you use it with anything else such as taxonomies, users or options, you need to give ACF a hint about how to look it up. In this case you need to tell it what taxonomy and term you are specifically targeting. Luckily both WordPress and ACF make this really easy:
//Ask WordPress for the currently queried object
//http://codex.wordpress.org/Function_Reference/get_queried_object
$obj = get_queried_object();
//Pass that object as a second parameter into get_field
$destination_landing_image = get_field( 'destination_landing_image', $obj );
I'm using wordpress, and I'm trying to create custom descriptions for categories pages.
I have modified its header.php file to echo custom titles and descriptions. But Wordpress is replacing my meta description with that of first post.
How can I stop this?
My Code:
echo '<meta name="description" content="'.$desc.'" />';
I'm using eMovies Theme: http://fthemes.com/emovies-free-wordpress-theme/
My site category link: http://www.raagalu.in/category/telugu-songs/
I even tried using plugins like "Category SEO Meta Tags", but no use. It is just creating two meta descriptions.
Please help me fix this.
<?php single_cat_title(); ?>
If you are on a category or template page.
See http://codex.wordpress.org/Function_Reference/single_cat_title