5
votes

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_query_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?

2

2 Answers

3
votes

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
votes

I always like to use #BW custom sidebar blocks plugin, because it basically makes like a new page type which you can then input into any widget area, it basically gives my clients full control of what will be in their sidebars via the wordpress editor. Hope that helps.