基本上我有 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/
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/389811.html
