2016-10-25 159 views
0

我會知道我怎麼能在一個Wordpress類別頁面(category.php)的子類別和這個子類別的職位?如何獲得類別頁面的子類別和帖子?

我現在有下面的代碼,並在那裏的「echo 'test';」ist我想顯示的父類別的職位。

<?php 
$args = array('child_of' => get_query_var('cat')); 
$categories = get_categories($args); 

$numOfItems = 20; // Set no of category per page 
$page = isset($_GET['cpage']) ? abs((int) $_GET['cpage']) : 1; 
$to = $page * $numOfItems; 
$current = $to - $numOfItems; 
$total = sizeof($categories); 

echo '<ul class="cat-content">'; 
for($i=$current; $i<$to; ++$i) { 
    $category = $categories[$i]; 
    if($category->name) { 
     echo '<li><h2>'. $category->name.'</h2>'; 

     echo 'test'; 

     echo '</li>'; 
    } 
} 
echo '</ul>'; 

unset($category); 

?> 

回答

0

將此處設置爲echo "test";

// The Query 
$args = array('post_type' => post, 'posts_per_page' => -1, 'cat' => $category->term_id); 
$the_query = new WP_Query($args); 

// The Loop 
if ($the_query->have_posts()) { 
    echo '<ul>'; 
    while ($the_query->have_posts()) { 
     $the_query->the_post(); 
     echo '<li><a href="'.get_permalink().'" >' . get_the_title() . '</a></li>'; 
    } 
    echo '</ul>'; 
    /* Restore original Post Data */ 
    wp_reset_postdata(); 
} else { 
    // no posts found 
} 
+0

嗨@WordpressDave 非常感謝。它爲我工作。我還需要獲得帖子鏈接。現在我只有標題。我怎樣才能得到鏈接? – mradovac

+0

嗨看我的編輯。 – WordpressDave

相關問題