首页 文章

需要帮助将wordpress类别链接添加到现有主题小部件

提问于
浏览
0

我不是新编辑网站,但PHP也可能是外语,所以任何帮助将不胜感激!我有一个现有的wordpress主题,其自定义类别小部件在一侧显示产品滑块,然后显示具有类别 Headers 的类别图像 . 我希望链接到类别的 Headers 或链接的图像和 Headers . 我附上了我认为显示图像和 Headers 的部分代码 .

<section class="category_product">
        <div class="ak-container">
            <?php
            echo $before_widget;
            ?>
            <div class="feature-cat-product-wrap">
            <?php //if($product_alignment == 'left_align'): ?>
                <div class="feature-cat-image <?php echo $product_alignment;?>">
                    <?php 
                    $thumbnail_id = get_woocommerce_term_meta($product_category, 'thumbnail_id', true);
                    if (!empty($thumbnail_id)) {
                        $image = wp_get_attachment_image_src($thumbnail_id, 'prod-cat-size');
                        echo '<img src="' . esc_url($image[0]) . '" alt="asfds"  />';
                    }
                    else{ ?>
                    <img src="<?php echo get_template_directory_uri().'../images/dummy-cat.jpg'?>"/>
                    <?php } ?>
                    <div class="product-cat-desc">
                        <?php 

                        $taxonomy = 'product_cat';
                        $terms = term_description( $product_category, $taxonomy );
                        $terms_name = get_term( $product_category, $taxonomy );
                        ?>

                        <h3><?php echo $terms_name->name ?></h3>
                        <div class="cat_desc">  
                       <?php echo $terms; ?> 
                        </div>  
                    </div>
                </div>

如果需要更多代码段,请告诉我

1 回答

  • 0

    你可以使用get_term_link(); .

    将此功能轻松地添加到您当前的代码中可以让我们链接 Headers :

    <?php
    $taxonomy = 'product_cat';
    $terms = term_description( $product_category, $taxonomy );
    $terms_name = get_term( $product_category, $taxonomy );
    $terms_link = get_term_link( $terms_name )
    ?>
    
    <h3><a href="<?php echo $terms_link; ?>"><?php echo $terms_name->name ?></a></h3>
    

    如果要链接图像,则必须将找到链接的代码移动到输出图像的代码上方,然后执行类似操作 . 如果您真的想要链接图片并且无法使其工作,请在下方发表评论,我会帮助您 . 我鼓励你先尝试一下,编码是一项有用的技巧 .

相关问题