Add page to sidebar

So, I have a page called "breaking news" and using the 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 created a page element and put some content on this page. Now I want to show the content in the sidebar. How can i do this?

I 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 work. 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?

+4
source share
2 answers

To request a specific page by name, you do this:

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

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

I just showed it as an example, please report:

The query_posts function is intended to change only the main loop of the main page. It is not intended to create secondary loops on a page. If you want to create separate loops outside the main, you should use get_posts (). Using query_posts on loops other than the main one may cause your main loop to become incorrect and possibly display something you did not expect.

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

+2
source

I always like to use the plugin with custom #BW sidebars, because it basically looks like a new page type, which can then be entered into any widget area, and basically gives my clients complete control over what will be in their sidebars through wordpress editor. Hope this helps.

0
source

All Articles