2010-09-20 221 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编辑器完全控制其侧边栏中的内容。希望有所帮助。