get_queried_object() - > image;无法获得图像

时间:2016-03-21 07:32:36

标签: php wordpress taxonomy custom-taxonomy

我为产品创建了自定义分类。在自定义分类中,用户可以输入名称并可以上传图像。在产品页面中,我可以获得图像和类别标题。当用户点击它时,它移动到下一页,其中显示了帖子和标题的描述。

我也希望在下一页中获得图像。

以下是代码:用于显示自定义类别

foreach($terms as $term) {

    $prod_meta = get_option("taxonomy_term_".$term->term_id);

    if(($counter % 4) == 0) {
        echo '<div class="row product-gallery">';
    }
    ?>
    <div class="col-sm-3">
        <div class="product-warp">
            <div class="product">
                <a href="#"><img src="<?php echo $prod_meta['img']; ?>" title="" alt=""></a>
            </div>
            <div class="product-name">
                <h5>
                    <a href="<?php echo get_term_link($term->slug, 'product_categories') ?>">
                        <?php echo $term->name; ?>
                    </a>
                </h5>
            </div>
        </div>
    </div>

有关产品详细信息页面

<?php
get_header();

$slug = get_queried_object()->slug; // get clicked category slug
$name = get_queried_object()->name; // get clicked category name

$tax_post_args = array(
    'post_type' => 'products', // your post type
    'posts_per_page' => 999,
    'orderby' => 'id',
    'order' => 'ASC',
    'tax_query' => array(
        array(
            'taxonomy' => 'product_categories', // your taxonomy
            'field' => 'slug',
            'terms' => $slug
        )
    )
);
$tax_post_qry = new WP_Query($tax_post_args);

if ($tax_post_qry->have_posts())
    while($tax_post_qry->have_posts()) :
        $tax_post_qry->the_post(); ?>

        <div class="row product-details">
        <div class="col-sm-7">
        <div class="fire-product">
        <h4><?php the_title(); ?></h4>

        <?php the_content(); ?>

0 个答案:

没有答案