简体   繁体   English

PHP 执行两次的问题

[英]Issue with PHP executing twice

I am displaying a list of filters using Isotope.我正在使用同位素显示过滤器列表。 The functionality works when the first part of the code works however, when the screen is resized the posts don't filter when it executes the last part... Any help is much appreciated!该功能在代码的第一部分工作时起作用,但是,当调整屏幕大小时,帖子在执行最后一部分时不会过滤......非常感谢任何帮助!

<?php
    $filterLinks = array();
    $newarray = array();
    $starter = array('name'=>'View All','slug'=>'*');
    $filterLinks[] = $starter;
    $taxterms = get_terms( $customTax );
    if ( ! empty( $taxterms ) && ! is_wp_error( $taxterms ) ){
      foreach ( $taxterms as $taxterm ) {
        $datafilter = '.' . $taxterm->slug;
        $newarray = array(
          'name' => $taxterm->name,
          'slug' => $datafilter,
        );
        $filterLinks[] = $newarray;
      }
    }
    echo '<ul id="filters" class="desk-filters button-group">' ."\n";
    foreach ($filterLinks as $links) {
      echo '<li><button class="button" data-filter="' . $links['slug'] . '">' . $links['name'] . '</button></li>'."\n";
    }
    echo '</ul>';

    // Drop down menu on mobile
    echo '<div id="filters" class="resp-filters button-group">'."\n";
    echo '<div class="resp-filter-btn">Select Filter</div>'."\n";
    echo '<div class="resp-filter-content">'."\n";
    foreach ($filterLinks as $links) {
      echo '<a class="button" data-filter="' . $links['slug'] . '">' . $links['name'] . '</a>'."\n";
    }
    echo '</div>'."\n";
    echo '</div>';
?>

Functionality Works:功能作品:

echo '<ul id="filters" class="desk-filters button-group">' ."\n";
  foreach ($filterLinks as $links) {
    echo '<li><button class="button" data-filter="' . $links['slug'] . '">' . $links['name'] . '</button></li>'."\n";
  }
echo '</ul>';

Functionality Doesn't Work:功能不起作用:

// Drop down menu on mobile
echo '<div id="filters" class="resp-filters button-group">'."\n";
echo '<div class="resp-filter-btn">Select Filter</div>'."\n";
echo '<div class="resp-filter-content">'."\n";
foreach ($filterLinks as $links) {
  echo '<a class="button" data-filter="' . $links['slug'] . '">' . $links['name'] . '</a>'."\n";
}
echo '</div>'."\n";
echo '</div>';

Is this because i'm executing it twice, just hiding one on desktop and showing the other on mobile?这是因为我执行了两次,只是在桌面上隐藏一个并在移动设备上显示另一个?

Looking for some direction.寻找一些方向。 Thanks in advance!提前致谢!

You're using id="filters" twice, which is improper use of the id attribute, since it should be unique.您使用了id="filters"两次,这是对 id 属性的不当使用,因为它应该是唯一的。 Not sure if that is of any concern?不知道这是否有任何问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM