拨开荷叶行,寻梦已然成。仙女莲花里,翩翩白鹭情。
IMG-LOGO
主页 文章列表 我的自定义分类url链接的页面没有显示

我的自定义分类url链接的页面没有显示

白鹭 - 2022-02-11 2002 0 0

基本上我有 newsletter.php 页面,其中显示了所有现有的自定义帖子。从这里,我有一个下拉类别串列,您可以按类别过滤自定义帖子。单击特定类别后,它将转到 pdf_cat.php 以显示过滤后的输出。问题是结果页面项没有显示出来。你能帮我弄清楚这里的逻辑吗?到目前为止,这是我的代码:

来自 newsletter.php --> 下拉类别按钮:

<select name="form" id="form">
   <div class="options">
      <option value="<?php echo home_url('/newsletter'); ?>" selected>一覧</option>                                   
         <?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  value="'. get_term_link($term->term_id) .' ">' . $term->name . '</option>';                                                

            }
         ?>   
     </div>   
   </select>

我的 JS 触发 url 链接:

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

我的 pdf_cat.php 页面应该显示过滤结果:

  <?php
    $terms = get_the_terms();                    // 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()
    ?>

谁能帮我解决这个问题?我希望这次我解释清楚。

uj5u.com热心网友回复:

你只需要把你的pdf_cat.php改成taxonomy.php,然后让wordpress为你打开taxonomy id链接^^

检查此链接https://wphierarchy.com/

标签:

0 评论

发表评论

您的电子邮件地址不会被公开。 必填的字段已做标记 *