2010-09-20 217 views
4

所以我有一個所謂的「最新消息」,並使用自定義模板頁面t_latest_news.php添加頁面側邊欄

 
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
<div class="latest-news" id="post-<?php the_ID(); ?>"> 
<?php the_content(); ?> 
<?php edit_post_link('Edit this page','<p class="edit-link">','</p>'); ?> 
</div><!-- /.latest-news --> 
<?php endwhile; endif; ?> 

我創建了一個頁面項目,並把一些內容放到這個頁面。現在,我想在側邊欄上顯示內容。我該怎麼做?

我已經試過類似:

 
<?php include(get_query_template('t_latest_news.php')); ?> 
<?php include(TEMPLATEPATH . 't_latest_news.php'); ?> 
<?php get_query_template('t_latest_news.php') ?> 
<?php get_template_part('t_latest_news.php'); ?> 

但他們沒有工作。幫幫我!


 
<?php query_posts('page_id=76'); ?> 
<?php while (have_posts()) { the_post(); ?> 
    <h2><?php the_title(); ?></h2> 
    <?php the_content(); ?> 
<?php } ?> 
<?php wp_reset_query(); ?> 

它與 「PAGE_ID」,而不是頁面名。任何想法?

回答

2

按名稱查詢特定的頁面你這樣做:

<?php 
query_posts('pagename=about'); //retrieves the about page only 
?> 

你應該末刪除.php爲,以便它讀取t_latest_news

我只是顯示這個作爲例如,請注意:

query_posts函數僅用於修改主頁面Loop。它並不是用來在頁面上創建輔助循環的手段。如果你想在主函數之外創建單獨的循環,你應該使用get_posts()來代替。在主循環以外的循環上使用query_posts可能會導致主循環變得不正確,並可能顯示您不期望的內容。

看到:http://codex.wordpress.org/Template_Tags/get_posts瞭解更多信息

+0

我已經把這個,但似乎並沒有工作。 <?php query_posts('pagename = t_latest_news'); ?> – solidcolour 2010-09-20 17:21:19

0

我總是喜歡用#BW自定義側邊欄插件模塊,因爲它基本上使得像一個新的頁面類型,然後可以輸入到任何按鈕區,它基本上是給我的客戶通過wordpress編輯器完全控制其側邊欄中的內容。希望有所幫助。