0 レビュー
1 回答
php --jQuery-divにコンテンツがあるかどうかを確認し、ない場合はクラスをトップレベルのdivに追加します
誰かが私を助けてくれることを本当に望んでいます。このページで問題が発生しています: http://dd-server.co.uk/vinetrail/producers/
各地域には、折りたたみ可能なdivを介して表示される多数のプロデューサーがあります。すべて正常に機能していますが、ページの上部にあるフィルターを使用すると、空の領域が表示されていることを除いて、正常に機能します。
jQueryを使用して空のdivを検出し、リージョン全体を非表示にしたいので、プロデューサーのあるリージョンのみが表示されます。これが私のコードです:
<div id="producer-list">
<?php
$region_group_terms = get_terms( 'producer_region' );
$c = 0;
$id = 'section1';
foreach ( $region_group_terms as $region_group_term ) {
$c++;
$producers_query = new WP_Query( array(
'post_type' => 'producers',
'orderby' => 'title',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'producer_region',
'field' => 'slug',
'terms' => array( $region_group_term->slug ),
'operator' => 'IN'
)
),
'search_filter_id' => 788
) );
?>
<div class="pro-wrap">
<?php if($c == 1) : ?>
<div class="collapsible collapse-open" id="<?php echo $id; ?>"><h2><?php echo $region_group_term->name; ?><span></span></h2></div>
<?php else : ?>
<div class="collapsible" id="<?php echo $region_group_term->name; ?>"><h2><?php echo $region_group_term->name; ?><span></span></h2></div>
<?php endif; ?>
<div class="container">
<div class="content">
<?php
if ( $producers_query->have_posts() ) : while ( $producers_query->have_posts() ) : $producers_query->the_post(); ?>
<div class="one-quarter">
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php echo get_permalink(); ?>"><?php echo get_the_post_thumbnail(); ?></a>
<?php else : ?>
<a href="<?php echo get_permalink(); ?>"><img src="<?php echo get_template_directory_uri(); ?>/img/producer-default.jpg" alt="<?php echo the_title(); ?>" /></a>
<?php endif; ?>
<h3>
<a href="<?php echo the_permalink(); ?>">
<?php echo $region_group_term->name; ?>
<span><?php echo the_title(); ?></span>
</a>
</h3>
</div>
<?php endwhile; endif; ?>
<?php
$member_group_query = null;
wp_reset_postdata();
?>
</div>
</div>
</div>
<?php } ?>
</div>
わからない
0
レビュー
答え :
解決策:
jQueryでこれを試すことができます
1を試す
jQuery( document ).ready(function() { // Loop over hidden element with class container jQuery.each(jQuery('.pro-wrap .container:hidden'), function(i, ele){ // Hide closest parent found with class pro-wrap jQuery(ele).closest('.pro-wrap').hide(); }); });
2を試す
jQuery( document ).ready(function() { // Loop over element with class content jQuery.each(jQuery('.pro-wrap .container .content'), function(i, ele){ var jEle = jQuery(ele); // If empty content if (jEle.text().trim().length == 0) { // Hide closest parent found with class pro-wrap jEle.closest('.pro-wrap').hide(); } }); });
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。