开发者

add a page to sidebar

So I have a page called "latest news" and using a custom template 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; ?>

I've created a page item and put some content into that page. Now, I want to show the content on the sidebar. How can I do that please?

I've tried something like:

<?php include(get_query_template('t_latest_news.php')); ?>
<?php include(TEMPLATEPATH . 't_latest_news.php'); ?>
<?php get_qu开发者_StackOverflow社区ery_template('t_latest_news.php') ?>
<?php get_template_part( 't_latest_news.php' ); ?>

But none of them works. HELP!


<?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(); ?>

It works with "page_id" but not pagename. any idea?


To query a specific page by name you do this:

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

You should remove the .php at the end so that it reads t_latest_news

I was just showing this as an example, please be advised:

The query_posts function is intended to be used to modify the main page Loop only. It is not intended as a means to create secondary Loops on the page. If you want to create separate Loops outside of the main one, you should use get_posts() instead. Use of query_posts on Loops other than the main one can result in your main Loop becoming incorrect and possibly displaying things that you were not expecting.

see: http://codex.wordpress.org/Template_Tags/get_posts for more information

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜