2016-03-08 35 views
1

我正在使用wp_get_archives函數來顯示我的側邊欄上的帖子列表。目前這確實按預期工作。存檔參數不循環

我想在此邊欄上顯示get_the_title()get_the_excerpt()。這些也起作用。

但是,他們只顯示當前的標題和摘錄,而不是相應的標題和摘錄到當前帖子。

實施例:

張貼1顯示張貼1的標題和摘要。

帖子2顯示帖子1的標題和摘錄。

這裏是我的全部側邊欄:

<aside id= "homeSideBar"> 
    <?php if (have_posts()) { 
     while (have_posts()) { 
      the_post(); ?> 
    <?php }} 
    wp_get_archives(array('type' => 'postbypost', 'limit' => 10, 'after' => "<img class='showExcerpt' src=\"" . get_template_directory_uri() ."/images/plus-circle.png\"><div class='postExcerpt'><h1 class='fitHeadliner'>" . get_the_title() . "</h1><p>" . get_the_excerpt() . "</p><div class='hideExcerpt'>X</div></div>")); ?> 

    <a href="/index.php?page_id=4">...</a> 

</aside> 

我怎樣才能讓我的帖子顯示其相應的標題和摘錄?

+0

能否請您解釋一下這個問題更多..你放置get_the_title()和get_the_excerpt( )函數在while循環之外..請告知確切需要輸出的內容 –

+0

當在循環中放置'wp_get_archives()'函數時,它顯示的文檔數量與有帖子的次數相同。目前該函數返回鏈接到最後10個鏈接的帖子列表。我想使用'wp_get_archives'的'after'參數添加摘錄和標題 – Chris

回答

0

所以當我的邊欄變得更多的參與時,我認爲最好重構並創建一個sidebar.php模板。

在我的sidebar.php模板我用get_posts()get_posts()可以使用setup_postdata($post)全球化後的信息像the_excerpt()the_title()