在侧边栏中添加页面

sol*_*our 5 wordpress

所以我有一个名为"最新消息"的页面并使用自定义模板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"但不适用于pagename.任何的想法?

Tod*_*ses 5

要按名称查询特定页面,请执行以下操作:

<?php
query_posts('pagename=about'); //retrieves the about page only
?>
Run Code Online (Sandbox Code Playgroud)

您应该删除末尾的.php,以便它读取t_latest_news

我只是举个例子,请注意:

query_posts 函数仅用于修改主页循环。它并非旨在作为在页面上创建辅助循环的方法。如果您想在主循环之外创建单独的循环,则应该使用 get_posts() 。在主循环以外的循环上使用 query_posts 可能会导致主循环变得不正确,并可能显示您不期望的内容。

请参阅: http: //codex.wordpress.org/Template_Tags/get_posts了解更多信息