0

仍在尝试弄清楚如何过滤自定义分类并显示它。JS 用于触发生成的 URL 工作正常。问题是结果页面项目未显示。到目前为止我有这个代码:

                  <?php
                    $args = array(
                      'orderby' => 'slug',
                      'order' => 'ASC',
                      'parent' => 0,
                      'hide_empty' => false
                   );
                   $terms = get_terms([
                      'taxonomy' => 'pdf_cat',
                      'hide_empty' => false,
                     ]);
                      foreach( $terms as $term ){
                       echo '<option class="ctg" value="'. get_term_link($term->term_id) .' ">' . $term->name . '</option>';                                                
                   }
      

//下一个代码是点击显示后获取类别ID

                <?php
                  $terms = get_terms([
                    'taxonomy' => 'pdf_cat',
                    'hide_empty' => false,
                    ]);                                         // get the category from query
                  $terms = $term[0];                                        
                  $term_name = get_term_name($term->name);     // get the category name
                  $term_id = get_term_ID($term->term_id);      // get the catehory ID
                ?>
      
              

                 <?php
                      $paged = get_query_var('paged', 1);
                      $args = array(                          // asigned the functions inside the array
                          'paged' => $paged,
                          'post_type' => 'pdf',
                          'taxonomy' => $term_id,
                      );
                      $query = new WP_Query($args);          // get the functions inside the assigned name 
             
                  global $query_string; //Post the specify numbers per page
                  query_posts( $query_string . "&posts_per_page=12&paged=".$paged );
                  while ( have_posts() ) : the_post()
                ?>

这是点击时触发下拉菜单链接的js:

            <script type="text/javascript">
                $("#form").change(function(){
                var url = $(this).val();
                location.assign(url);
                });
            </script>

//下一个代码显示

                     <div class="pdf-box">
                        <?php
                        $file = get_field('file');
                        if( $file ): ?>
                            <a href="<?php echo $file['url']; ?>" target="_blank"><?php echo $file['file']; ?>
                                <div class="service-list-col1">
                                <i class="fa-file-o"></i>
                                </div>
                                <div class="service-list-col2">
                                    <p><?php the_time('Y.m.d'); ?></p>
                                    <h3><?php the_title(); ?></h3>
                                </div>
                            </a>
                        <?php endif; ?>
                    </div>
4

0 回答 0