我在我的产品页面上有一个锚定链接,链接到页面下方的一个div。div仅在有内容时显示。
是否可以基于div ID为链接编写if语句?是否存在#ID?
这是div:
<div class="upsells products" id="tab-accessories">
<!--Change related products text-->
<?php
global $post;
//If Product Page is a Model page, display "Reccomended Accessories"
if ( has_term( \'Models\', \'product_cat\', $post->ID ) ) {
echo \'<h2>\' . \'Reccomended Accessories\' . \'</h2>\';
}
//If Product Page is an Accessories page, display "Customers Also Bought"
if ( has_term( \'Accessories\', \'product_cat\', $post->ID ) ) {
echo \'<h2>\' . \'Customers Also Bought\' . \'</h2>\';
}
?>
<?php woocommerce_product_loop_start(); ?>
<?php while ( $products->have_posts() ) : $products->the_post(); ?>
<?php wc_get_template_part( \'content\', \'product\' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
</div>
这是链接: <li><a href="#tab-accessories">Accessories</a></li>