2012-06-16 54 views
1

我用下面的代碼創建了一個自定義的側邊欄-wallside-sidebar.php。除了鏈接以外,一切都很完美。get_category_link()沒有顯示任何內容

<div id="wallpaper-categories" class="widget widget_categories"> 
    <h4 class="widgettitle">Wallpaper Categories</h4> 
    <ul> 
    <?php 
     $args = array('type' => 'post' , 'taxonomy' => 'wallpaper' , 'order' => 'ASC' , 'orderby' => 'name'); 
     $categories = get_categories($args); 
     foreach ($categories as $category) { 
    ?> 
     <li class="cat-item cat-item-<?php echo $category->cat_ID; ?>"> 
      <a title="<?php echo sprintf(__("View all posts in %s"), $category->name); ?>" href="<?php get_category_link($category->term_id); ?>"><?php echo $category->name; ?></a> 
     </li> 
    <?php 
     } 
    ?> 
    </ul>  
</div> 

回答

0

get_category_link()只返回鏈接,但不打印它。您需要將<?php get_category_link($category->term_id) ?>更改爲<?php echo get_category_link($category->term_id) ?>

這也是最有可能的罪魁禍首,在大多數情況下,需要打印但不是,因此缺少echo是您應該檢查這種情況下的第一件事。

此外,請嘗試將get_category_link($category->term_id)更改爲get_category_link($category->cat_ID)。我看到WP Codex中的get_categories示例使用term_id,但get_category_link的文檔明確聲明它期望通過類別ID。

+0

我也試過這種..但同樣的..沒有結果。 –

+0

查看其他可能解決方案的更新答案。 – lanzz

0

嘗試這樣的:

<?php echo get_category_link($category->term_id); ?>