【发布时间】:2012-12-21 16:57:09
【问题描述】:
我有一个单一的.php,我在其中显示一个产品。我有此产品的类别和子类别,我想在底部显示来自类似类别的自定义字段图像。
例如,我在 Red Bag 1 中,我想在底部放置一个 缩略图 类似页面,例如 Red Bag 2和 Red Bag 3 属于同一类别“Red Bag”
我实际上已经有一个代码,但我不知道如何定位由 Advance Custom Field 插件创建的自定义字段:the_field("product_image")
这是我的代码:
<?php
global $post;
$cat_ID=array();
$categories = get_the_category(); //get all categories for this post
foreach($categories as $category) {
array_push($cat_ID,$category->cat_ID);
}
$args = array(
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post',
'numberposts' => 8,
'post__not_in' => array($post->ID),
'category__in' => $cat_ID
); // post__not_in will exclude the post we are displaying
$cat_posts = get_posts($args);
$out='';
foreach($cat_posts as $cat_post) {
$out .= '<li>';
$out .= '<a href="'.get_permalink($cat_post->ID).'" title="'.wptexturize($cat_post->post_title).'">'.wptexturize($cat_post->post_title).'</a></li>';
}
$out = '<ul class="cat_post">' . $out . '</ul>';
echo $out;
?>
.wptexturize($cat_post->post_title). 假设是图像而不是标题。图片来源应取自自定义字段the_field("product_image")
【问题讨论】:
标签: wordpress