Woocommerce - 循环添加产品链接

时间:2014-03-14 17:24:49

标签: php wordpress hyperlink woocommerce

我觉得这应该很简单,但我一直在寻找15分钟而且无法在任何地方找到它:

我有一个循环列出某个类别的产品,我需要对其进行修改,以便图片和标题是指向单个产品页面的链接。我正在寻找这样的东西。

<a href="<?php echo woocommerce_get_the_permalink() ?>">

这就是我所拥有的:

 <?php
    $args = array( 'post_type' => 'product', 'posts_per_page' => 4, 'product_cat' => 'power-chairs', 'orderby' => 'ID' );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
            <div class="product">  
                <div class="padding">
                        <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder"/>'; ?>
                        <p class="caption"><?php the_title(); ?></p>
                </div><!-- padding -->
            </div><!-- product -->
<?php endwhile; ?>

编辑:找到它 - 它是href =“get_permalink($ product_id)”

1 个答案:

答案 0 :(得分:0)

您是否尝试在图片和标题周围添加a href链接:

<?php
$args = array( 'post_type' => 'product', 'posts_per_page' => 4, 'product_cat' => 'power-chairs', 'orderby' => 'ID' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
        <div class="product">  
            <div class="padding">
                   <a href="<?php echo woocommerce_get_the_permalink() ?>">

                    <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder"/>'; ?></a>
                    <p class="caption"><a href="<?php echo woocommerce_get_the_permalink() ?>"><?php the_title(); ?></a></p>

            </div><!-- padding -->
        </div><!-- product -->