我正在嘗試在博客文章中展示“特色產(chǎn)品”。這些特色產(chǎn)品將通過每個(gè)帖子后端的自定義字段帖子對(duì)象進(jìn)行選擇。我已經(jīng)寫下了我認(rèn)為 PHP 應(yīng)該是什么 - 我哪里出錯(cuò)了?當(dāng)我嘗試使用短代碼時(shí),沒有出現(xiàn)任何代碼(但短代碼文本沒有顯示,因此肯定已添加)。謝謝 :) <?phpadd_shortcode('featuredproducts' , 'printfeaturedprod');function printfeaturedprod(){ $html = '';$instruments = get_field('featuredprod');if( $instruments ): $html .= '<div class="featuredproducts">'; $html .= '<h2 style="font-size:18px; font-family:poppins;">Featured in this video</h2>'; foreach( $instruments as $instruments ): $permalink = get_permalink( $instruments->ID ); $title = get_the_title( $instruments->ID ); $product = wc_get_product( $instruments->ID ); $price = $product->get_price(); $featured_img_url = get_the_post_thumbnail_url($instruments->ID, 'full'); $html .= '<div class="featuredproduct">'; $html .= '<img class="featuredproductimg" src="' . $featured_img_url . '">'; $html .= '<div class="proddetails">'; $html .= '<a class="producttitle" href="' . $permalink . '"><?php echo esc_html( $title ); ?></a>'; $html .= '<br><span class="productprice">£' . $price . '</span>'; $html .= '</div>'; $html .= '</div>'; endforeach; $html .= '</div>'; endif;}
如何使用帖子上的短代碼調(diào)用帖子對(duì)象(產(chǎn)品)自定義字段
翻翻過去那場(chǎng)雪
2023-09-22 14:56:53