I am trying to add multiple product categories -to display category thumbnail has product badge in catalog page
add_action ('woocommerce_before_shop_loop_item_title','alt_category_badge', 99);
add_action ('woocommerce_product_thumbnails','alt_category_badge', 100);
function alt_category_badge() {
global $product;
if ( is_product()){
global $post;
$brands_id = get_term_by('slug', 'sunglasses', 'product_cat');
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ){
if($term->parent === $brands_id->term_id) {
$category_name = $term->name;
$category_thumbnail = get_woocommerce_term_meta($term->term_id, 'thumbnail_id', true);
$image = wp_get_attachment_url($category_thumbnail);
if ( $image )
echo '<div class="brand-icon-logo sunglasses" ><img height="100%" width="35%" src="'.$image.'" alt="'.$category_name.' sunglasses online in dubai"></div>';
}
}
}
}
/**
* Display product category thumbnail.
*
*/
add_action('woocommerce_before_shop_loop_item_title', 'display_product_category_thumbnail', 20);
function display_product_category_thumbnail()
{
global $product;
$productFirstCategory = reset(get_the_terms($product->get_id(), 'product_cat'));
$small_thumb_size = 'woocommerce_thumbnail';
$dimensions = wc_get_image_size($small_thumb_size);
if ($thumbnail_id = get_term_meta($productFirstCategory->term_id, 'thumbnail_id', true)) {
$image = wp_get_attachment_image_src($thumbnail_id, $small_thumb_size);
if (is_array($image)) {
$image = reset($image);
}
$image_srcset = function_exists('wp_get_attachment_image_srcset') ? wp_get_attachment_image_srcset($thumbnail_id, $small_thumb_size) : false;
$image_sizes = function_exists('wp_get_attachment_image_sizes') ? wp_get_attachment_image_sizes($thumbnail_id, $small_thumb_size) : false;
} else {
$image = wc_placeholder_img_src();
$image_srcset = false;
$image_sizes = false;
}
if ( $image )
echo '<div class="brand-icon-logo sunglasses" ><img height="100%" width="35%" src="'.$image.'" alt="'.$category_name.' sunglasses online in dubai"></div>';
}
for specific categorys
/**
* Display product category thumbnail.
*
*/
add_action('woocommerce_before_shop_loop_item_title', 'display_product_category_thumbnail', 20);
function display_product_category_thumbnail()
{
global $product;
if ( has_term( array( 'catagory1','catagory2'), 'product_cat', $product->get_id() ) ){
$productFirstCategory = reset(get_the_terms($product->get_id(), 'product_cat'));
$small_thumb_size = 'woocommerce_thumbnail';
$dimensions = wc_get_image_size($small_thumb_size);
if ($thumbnail_id = get_term_meta($productFirstCategory->term_id, 'thumbnail_id', true)) {
$image = wp_get_attachment_image_src($thumbnail_id, $small_thumb_size);
if (is_array($image)) {
$image = reset($image);
}
$image_srcset = function_exists('wp_get_attachment_image_srcset') ? wp_get_attachment_image_srcset($thumbnail_id, $small_thumb_size) : false;
$image_sizes = function_exists('wp_get_attachment_image_sizes') ? wp_get_attachment_image_sizes($thumbnail_id, $small_thumb_size) : false;
} else {
$image = wc_placeholder_img_src();
$image_srcset = false;
$image_sizes = false;
}
if ( $image )
echo '<div class="brand-icon-logo sunglasses" ><img height="100%" width="35%" src="'.$image.'" alt="'.$category_name.' sunglasses online in dubai"></div>';
}
}
Related
I'm trying to change default image placeholder for products with no images to images according to their product category.
I'm using:
add_filter( 'woocommerce_placeholder_img_src', 'my_custom_woocommerce_placeholder', 10 );
// Function to return new placeholder image URL.
function my_custom_woocommerce_placeholder( $image_url )
{
if ($product_category == 'category1') {
$image_url = 'http://website.com/imageforCategory.png';
}
elseif ($product_category == 'category2') {
$image_url = 'http://website.com/imageforCategory.png';
}
else
{
$image_url = 'http://website.com/defaultImage.png';
}
return $image_url;
}
I'm stuck at getting product category ($product_category) detected in functions.php file of my theme.
In content-single-product.php page I'm just defining
global $product
and then just using
$product->get_categories();
to get the category of product.
How do I do it in functions.php of my theme?
You could use has_term() - Checks if the current post has any of given terms.
So you get:
// Single product page
function filter_woocommerce_placeholder_img_src( $src ) {
// Get the global product object
global $product;
// Is a WC product
if ( is_a( $product, 'WC_Product' ) ) {
// Has term (product category)
if ( has_term( 'categorie-1', 'product_cat', $product->get_id() ) ) {
$src = 'http://website.com/imageforCategory1.png';
} elseif ( has_term( array('categorie-2', 'categorie-3'), 'product_cat', $product->get_id() ) ) {
$src = 'http://website.com/imageforCategory2.png';
}
}
return $src;
}
add_filter( 'woocommerce_placeholder_img_src', 'filter_woocommerce_placeholder_img_src', 10, 1 );
// Archive/Shop page
function filter_woocommerce_placeholder_img ( $image_html, $size, $dimensions ) {
$dimensions = wc_get_image_size( $size );
$default_attr = array(
'class' => 'woocommerce-placeholder wp-post-image',
'alt' => __( 'Placeholder', 'woocommerce' ),
);
$attr = wp_parse_args( '', $default_attr );
$image = wc_placeholder_img_src( $size );
$hwstring = image_hwstring( $dimensions['width'], $dimensions['height'] );
$attributes = array();
foreach ( $attr as $name => $value ) {
$attribute[] = esc_attr( $name ) . '="' . esc_attr( $value ) . '"';
}
$image_html = '<img src="' . esc_url( $image ) . '" ' . $hwstring . implode( ' ', $attribute ) . '/>';
return $image_html;
}
add_filter( 'woocommerce_placeholder_img', 'filter_woocommerce_placeholder_img', 10, 3 );
Note: the woocommerce_placeholder_img hook, used on archive/shop page returns $image_html. That string can be adapted to your needs. Such as image src, class, alt, size, etc ..
I'm looking for a way to target product variations and modify their prices based on the attributes each variation has. The below code is somewhat heading in the right direction, but instead of using product attributes to target variations, I'm relying on matching the variation's current price to a variable in order to target it. It works, but it leaves a ton of room for error with how vague it is.
add_filter('woocommerce_get_price','change_price', 10, 2);
function change_price($price, $productd){
if ( $productd->product_type == 'variation' || $productd->product_type == 'variable' ) {
$basicmp3 = 25;
$vprice = get_post_meta( $productd->variation_id, '_regular_price',true);
if ($vprice == $basicmp3) {
$vprice2 = $vprice * .5;
return $vprice2;
}
else{
return $vprice;
}
}
}
UPDATE Posted a working solution below
When you run a woocommerce class in a function, there's a need to call some global.
global $woocommerce; $product;
$product_variation = new WC_Product_Variation($_POST['variation_id']);
$regular_price = $product_variation->regular_price;
In other Word, it's not because you have $product as parameter that you can use the class functions (it's just a 'flatten' object like an array can be). You need to initialize a new object of a class to use $newproductobject->regular_price().
It's possible, if your code is part of a plugin that the woocommerce class are not yet load, then you'll need to include the file containing the class WC_Product _Variation. (Don't think it's the case)
Hope it helps !
Found a working solution. It's probably a little bloated since I'm no code master, but I does it's job! Below is a basic version, but this kind of flexibility will allow for more useful functions, such as automatically bulk discounting variation prices by user role for products who share certain attributes.
add_filter('woocommerce_get_price','change_price', 10, 2);
function change_price($price, $productd){
global $post, $woocommerce;
$post_id = $variation->ID;
$args = array(
'post_type' => 'product_variation',
'post_status' => array( 'private', 'publish' ),
'numberposts' => -1,
'orderby' => 'menu_order',
'order' => 'asc',
'post_parent' => $post->ID
);
$variations = get_posts( $args );
//declare variables for later use
$demomp3 = '';
$basicmp3 = '';
$basicwav = '';
$premiummp3 = '';
$premiumwav = '';
$syncmp3 = '';
$syncwav = '';
foreach ( $variations as $variation ) {
$variation_id = absint( $variation->ID );$variable_id = $this['variation_id'];
$variation_post_status = esc_attr( $variation->post_status );
$variation_data = get_post_meta( $variation_id );
$variation_data['variation_post_id'] = $variation_id;
//find attributes
$option1 = 'pa_license-options';
$option2 = 'pa_delivery-format';
$getmeta1 = get_post_meta($variation_id , 'attribute_'.$option1, true);
$getmeta2 = get_post_meta($variation_id , 'attribute_'.$option2, true);
$attribute1 = get_term_by('slug', $getmeta1, $option1);
$attribute2 = get_term_by('slug', $getmeta2, $option2);
$license = $attribute1->name;
$format = $attribute2->name;
//get the prices of each variation by the attribute combinations they have
if ($format === "mp3" && $license === "Demo License" ){
//retrieve variation price and assign it to the previously created variable
$demomp3 = get_post_meta($variation_id, '_regular_price', true );
}
if ($format === "mp3" && $license === "Basic License" ){
$basicmp3 = get_post_meta($variation_id, '_regular_price', true );
}
if ($format === "WAV" && $license === "Basic License" ){
$basicwav = get_post_meta($variation_id, '_regular_price', true );
}
if ($format === "mp3" && $license === "Premium License" ){
$premiummp3 = get_post_meta($variation_id, '_regular_price', true );
}
if ($format === "WAV" && $license === "Premium License" ){
$premiumwav = get_post_meta($variation_id, '_regular_price', true );
}
if ($format === "mp3" && $license === "Sync License" ){
$syncmp3 = get_post_meta($variation_id, '_regular_price', true );
}
if ($format === "WAV" && $license === "Sync License" ){
$syncwav = get_post_meta($variation_id, '_regular_price', true );
}
}
//Simple product doesn't need to be modified
if($productd->product_type == 'simple'){
return $price;
}
//adjust prices of variable products
if ( $productd->product_type == 'variation' || $productd->product_type == 'variable' ) {
$regprice = get_post_meta( $productd->variation_id, '_regular_price',true);
//target the current variation by matching its price to the one stored in the variable
if ($regprice == $demomp3) {
//apply price adjustment and return the new value
$price = $regprice * .5;
return $price;
}
else if ($regprice == $basicmp3) {
$price = $regprice * .5;
return $price;
}
else if ($regprice == $basicwav) {
$price = $regprice * .5;
return $price;
}
else if ($regprice == $premiummp3) {
$price = $regprice * .5;
return $price;
}
else if ($regprice == $premiumwav) {
$price = $regprice * .5;
return $price;
}
else if ($regprice == $syncmp3) {
$price = $regprice * .5;
return $price;
}
else if ($regprice == $syncwav) {
$price = $regprice * .5;
return $price;
}
else{
return $price;
}
}
}
Use the following script to update product variation. click here for detailed explanation.
https://www.pearlbells.co.uk/bulk-update-product-variation-price-woocommerce/
function getExistingProducts($updatedPrices,$skuArray) {
$loop = new WP_Query(array('post_type' => array('product', 'product_variation'), 'posts_per_page' => -1));
while ($loop->have_posts()) : $loop->the_post();
$id = get_the_ID();
$product = wc_get_product( $id );
$sku = get_post_meta($id, '_sku', true);
if( in_array( $sku, $skuArray ) ) {
$attributes = $product->get_attributes();
$attributes['medium-quantity-price']['value'] = $updatedPrices[$sku][4];
$attributes['low-quantity-price']['value'] = $updatedPrices[$sku][3];
// $attributes['v-low-quantity-price']['value'] = $updatedPrices[$sku][2];
update_post_meta( $id,'_product_attributes',$attributes);
echo ' Update Sku : '.$sku.' '.PHP_EOL;
}
endwhile;
}
I'm using WooCommerce and i want to show the product-category banner in product page.
for the product-category i used this code:
add_action( 'woocommerce_archive_description', 'woocommerce_category_image', 2 );
function woocommerce_category_image() {
if (is_product_category()){
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
if ( $image ) {
echo '<img src="' . $image . '" alt="" class="cat_ban"/>';
}
}
}
and for the product page i use a similar code with some changes,but it doesn't work,can some one point me to my mistake?
add_action( 'woocommerce_archive_description', 'woocommerce_product_image', 2 );
function woocommerce_product_image() {
if (is_product()){
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
$cat = $terms->term_id;
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
if ( $image ) {
echo '<img src="' . $image . '" alt="" class="cat_ban"/>';
}
}
}
found a solution on my own,hope it will help you:
add_action( 'woocommerce_before_single_product', 'woocommerce_product_image', 2 );
function woocommerce_product_image(){
$product_cats = wp_get_post_terms( get_the_ID(), 'product_cat' );
if ( $product_cats && ! is_wp_error ( $product_cats ) ){
$cat = array_shift( $product_cats );
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
$category_link = get_category_link($cat);
if ( $image ) {
echo '<img src="' . $image . '" alt="" class="cat_ban"/>';
}
}
}
You can add category banner to product page use this code -
add_action('woocommerce_before_single_product', 'woocommerce_add_category_banner', 2);
function woocommerce_add_category_banner()
{
global $product;
if (isset($product) && is_product())
{
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta($cat->term_id, 'thumbnail_id', true);
$image = wp_get_attachment_url($thumbnail_id);
if ($image)
{
echo '<img src="' . esc_url($image) . '" alt="" />';
}
}
}
I'm stuck trying to get my site together in time for our launch.
We've got a wordpress plugin that displays a product based on selected inputs. Each variation has an image which is layered over top of each other and in pNG to create a final picture. It all works well on the product page http://tattersfield.co/online-tailor-store/double-breasted/luciano-79000-1-jacket/ but now I need the image to display in our Composite Product area http://tattersfield.co/online-tailor-store/three-piece-single-breasted-suit/test-3-piece-suit .
This is the code I need to update to display the plugin generated image instead of the product thumbnail.
<?php
/**
* Composited Product Image
* #version 3.0.0
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) )
exit;
if ( has_post_thumbnail( $product_id ) ) {
?><div class="composited_product_images"><?php
$image_title = esc_attr( get_the_title( get_post_thumbnail_id( $product_id ) ) );
$image_link = wp_get_attachment_url( get_post_thumbnail_id( $product_id ) );
$image = get_the_post_thumbnail( $product_id, apply_filters( 'woocommerce_composited_product_thumbnail_size', 'shop_catalog' ), array(
'title' => $image_title
) );
echo apply_filters( 'woocommerce_composited_product_image_html', sprintf( '%s', $image_link, $image_title, $image ), $product_id );
?></div><?php
}
And this is a snippet of the code from the plugin that displays the image. What do I need to do to get these 2 pieces to work together to display the image I'm after?
Frontend Single Product Page
============================= */
public function display_product_image() {
global $post, $jckpc_options;
$setImages = get_post_meta( $post->ID, $this->slug.'_images', true );
$defaults = get_post_meta( $post->ID, $this->slug.'_defaults', true );
$querySelectors = $_GET;
if(!empty($querySelectors)) {
$sanitisedQuerySelectors = array();
foreach($querySelectors as $attSlug => $attVal) {
$sanitisedQuerySelectors[$this->sanitise_str($attSlug)] = $this->sanitise_str($attVal);
}
$querySelectors = $sanitisedQuerySelectors;
}
$images = array();
if( $setImages['background'] && $setImages['background'] != '' ) {
$imgSrc = wp_get_attachment_image_src($setImages['background'], apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ));
$images[] = '<img id="'.$this->slug.'_image_background" src="'.$imgSrc[0].'">';
}
$setImages = array_reverse($setImages);
$img_i = 1; foreach($setImages as $attSlug => $attVals) {
$default = ( isset($defaults[$attSlug]) && isset($setImages[$attSlug][$defaults[$attSlug]]) ) ? $setImages[$attSlug][$defaults[$attSlug]] : false;
$default = ( isset($querySelectors[$attSlug]) && isset($setImages[$attSlug][$querySelectors[$attSlug]]) ) ? $setImages[$attSlug][$querySelectors[$attSlug]] : $default;
$images[$img_i] = '<div id="'.$this->slug.'_image_'.$attSlug.'">';
if($default) {
$imgSrc = wp_get_attachment_image_src($default, apply_filters( 'single_product_large_thumbnail_size', 'shop_single' ));
$images[$img_i] .= '<img src="'.$imgSrc[0].'">';
}
$images[$img_i] .= '</div>';
$img_i++;
}
// output images
echo '<style>';
echo '#jckpc_images {';
// width
echo "width: {$jckpc_options['image_container_width']['width']};";
// align
if($jckpc_options['image_container_align'] == "centre") {
echo "margin-left: auto; margin-right: auto;";
$jckpc_options['image_container_align'] = "none";
}
echo "float: {$jckpc_options['image_container_align']};";
// spacing
echo "margin-top: {$jckpc_options['image_container_margin']['margin-top']};";
echo "margin-right: {$jckpc_options['image_container_margin']['margin-right']};";
echo "margin-bottom: {$jckpc_options['image_container_margin']['margin-bottom']};";
echo "margin-left: {$jckpc_options['image_container_margin']['margin-left']};";
// padding
echo "padding-top: {$jckpc_options['image_container_padding']['padding-top']};";
echo "padding-right: {$jckpc_options['image_container_padding']['padding-right']};";
echo "padding-bottom: {$jckpc_options['image_container_padding']['padding-bottom']};";
echo "padding-left: {$jckpc_options['image_container_padding']['padding-left']};";
// background
echo "background: {$jckpc_options['image_container_background']};";
echo '}';
$horThumbSpacing = $jckpc_options['thumb_spacing']/2;
$verThumbSpacing = $jckpc_options['thumb_spacing'];
echo "#jckpc_thumbnails {";
echo "margin: {$verThumbSpacing}px -{$horThumbSpacing}px -{$verThumbSpacing}px;";
echo "}";
echo '#jckpc_thumbnails a {';
echo "float: left;";
echo "display: inline;";
$thumbWidth = 100/(int)$jckpc_options['thumb_cols_rows'];
echo "width: {$thumbWidth}%;";
// spacing
echo "padding: 0 {$horThumbSpacing}px {$verThumbSpacing}px;";
echo '}';
echo "#jckpc_image_wrap #jckpc_loading {";
// background
echo "background: {$jckpc_options['loading_overlay_colour']};";
echo "}";
echo "#jckpc_image_wrap #jckpc_loading i {";
$loadingIconMTop = 20/2;
echo "font-size: 20px;";
echo "line-height: 20px;";
echo "margin-top: -{$loadingIconMTop}px;";
echo "color: {$jckpc_options['loading_icon_colour']};";
echo "}";
// breakpoint
if($jckpc_options['enable_breakpoint']) {
echo "#media (max-width: {$jckpc_options['breakpoint']['width']}) {";
echo '#jckpc_images {';
// width
echo "width: {$jckpc_options['image_container_width_breakpoint']['width']};";
// align
if($jckpc_options['image_container_align_breakpoint'] == "centre") {
echo "margin-left: auto; margin-right: auto;";
$jckpc_options['image_container_align_breakpoint'] = "none";
}
echo "float: {$jckpc_options['image_container_align_breakpoint']};";
// spacing
echo "margin-top: {$jckpc_options['image_container_margin_breakpoint']['margin-top']};";
echo "margin-right: {$jckpc_options['image_container_margin_breakpoint']['margin-right']};";
echo "margin-bottom: {$jckpc_options['image_container_margin_breakpoint']['margin-bottom']};";
echo "margin-left: {$jckpc_options['image_container_margin_breakpoint']['margin-left']};";
echo "}";
echo "}";
}
echo '</style>';
echo '<div id="'.$this->slug.'_images">';
echo '<div id="'.$this->slug.'_image_wrap" data-loading="0">';
foreach($images as $image) {
echo $image;
}
echo '<div id="'.$this->slug.'_loading"><i class="jckpc-icn-'.$jckpc_options['loading_icon'].' animate-spin"></i></div>';
echo '</div>';
if($jckpc_options['show_thumbs']) $this->get_thumbnails();
echo '</div>';
}
public function get_thumbnails() {
global $post, $product, $woocommerce;
$attachment_ids = $product->get_gallery_attachment_ids();
if ( $attachment_ids ) {
echo '<div id="'.$this->slug.'_thumbnails">';
$loop = 0;
$columns = apply_filters( 'woocommerce_product_thumbnails_columns', 3 );
foreach ( $attachment_ids as $attachment_id ) {
$classes = array( 'zoom' );
if ( $loop == 0 || $loop % $columns == 0 )
$classes[] = 'first';
if ( ( $loop + 1 ) % $columns == 0 )
$classes[] = 'last';
$image_link = wp_get_attachment_url( $attachment_id );
if ( ! $image_link )
continue;
$image = wp_get_attachment_image( $attachment_id, apply_filters( 'single_product_small_thumbnail_size', 'shop_thumbnail' ) );
$image_class = esc_attr( implode( ' ', $classes ) );
$image_title = esc_attr( get_the_title( $attachment_id ) );
echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', sprintf( '%s', $image_link, $image_class, $image_title, $image ), $attachment_id, $post->ID, $image_class );
$loop++;
}
echo '</div>';
}
}
public function get_image_data($pid, $atts) {
$imgData = array(
'prodid' => $pid
);
if(!empty($atts)){
foreach($atts as $attSlug => $attVal) {
if(substr($attSlug, 0, 10) != "attribute_") $attSlug = 'attribute_'.$attSlug;
$imgData[$attSlug] = sanitize_title_with_dashes($attVal);
}
}
A site of mine - http://www.sweetrubycakes.com.au - has recently had the thumbnails stop working (they were working up until yesterday, yesterday the domain registrar had some issues, but nothing else I know of could have caused it).
If you view the source, you'll see they include too much in the URL:
<img src="/home2/sweetrub/public_html/wp-content/uploads/et_temp/t-rex-tiny-63339_203x203.jpg" class="item-image" alt="T- Rexcellent">
where it should be:
<img src="/wp-content/uploads/et_temp/t-rex-tiny-63339_203x203.jpg" class="item-image" alt="T- Rexcellent">
I don't think I'm using the most recent version of the theme, however I've made some tweaks and don't wish to update.
The code that outputs that images is this:
<?php
$work_count = 0;
$recent_work_args = apply_filters( 'evolution_recent_work_args', array(
'showposts' => (int) get_option('evolution_posts_work_num'),
'category__not_in' => (array) get_option('evolution_exlcats_work')
) );
$recent_work_query = new WP_Query( $recent_work_args );
while ( $recent_work_query->have_posts() ) : $recent_work_query->the_post();
++$work_count;
$width = apply_filters( 'evolution_home_work_width', 203 );
$height = apply_filters( 'evolution_home_work_height', 203 );
$titletext = get_the_title();
$thumbnail = get_thumbnail($width,$height,'item-image',$titletext,$titletext,true,'Work');
$thumb = $thumbnail["thumb"];
$lightbox_title = ( $work_title = get_post_meta($post->ID, 'work_title',true) ) ? $work_title : $titletext;
$work_description = ( $work_desc = get_post_meta($post->ID, 'work_description',true) ) ? $work_desc : truncate_post( 50, false );
?>
<div class="r-work<?php if ( 0 == $work_count % 3 ) echo ' last'; ?>">
<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, 'item-image'); ?>
<span class="overlay"></span>
<!---->
<p><?php echo esc_html( $work_description ); ?></p>
</div> <!-- end .r-work -->
<?php endwhile; wp_reset_postdata(); ?>
And the print_thumbnail function looks like this:
if ( ! function_exists( 'print_thumbnail' ) ){
function print_thumbnail($thumbnail = '', $use_timthumb = true, $alttext = '', $width = 100, $height = 100, $class = '', $echoout = true, $forstyle = false, $resize = true, $post='') {
global $shortname;
if ( $post == '' ) global $post;
$output = '';
$thumbnail_orig = $thumbnail;
$thumbnail = et_multisite_thumbnail( $thumbnail );
$cropPosition = '';
$allow_new_thumb_method = false;
$new_method = true;
$new_method_thumb = '';
$external_source = false;
$allow_new_thumb_method = !$external_source && $new_method && $cropPosition == '';
if ( $allow_new_thumb_method && $thumbnail <> '' ){
$et_crop = get_post_meta( $post->ID, 'et_nocrop', true ) == '' ? true : false;
$new_method_thumb = et_resize_image( et_path_reltoabs($thumbnail), $width, $height, $et_crop );
if ( is_wp_error( $new_method_thumb ) ) $new_method_thumb = '';
}
if ($forstyle === false) {
$output = '<img src="' . esc_url( $new_method_thumb ) . '"';
if ($class <> '') $output .= " class='" . esc_attr( $class ) . "' ";
$output .= " alt='" . esc_attr( strip_tags( $alttext ) ) . "' />";
if (!$resize) $output = $thumbnail;
} else {
$output = $new_method_thumb;
}
if ($echoout) echo $output;
else return $output;
}
}
I've seen some other posts that suggest that it's a file permissions folder ( wp print_thumbnail function is not working ) but that doesn't seem to be working for me.
Does anyone have any suggestions?
I think print_thumbnail is the problem in your code. Instead of print_thumbnail try below options.
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail(); // Outputs <img/> object with src="thumbnail-href"
}
?>
Similarly, this would also work:
<?php
if ( has_post_thumbnail() ) {
echo( get_the_post_thumbnail( get_the_ID() ) );
}
?>
Check this stackoverflow answer