The only unusual part I could see was:
<?php get_a_post(25); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php get_a_post(29); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
Is get_a_post() a function that you created?
For those two queries I’d use WP_Query() instead. It’s explained better under “Multiple Loops in Action“.
Thread Starter
alfie
(@drtanz)
no get_a_post is a plugin http://guff.szub.net/2005/01/27/get-a-post/
I took off the code you mentioned but its still not working :S
Thread Starter
alfie
(@drtanz)
actually no, if i take off the code
<?php get_a_post(25); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php get_a_post(29); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
then the main content column repeats the posts that are shown in the sidebar, instead of displaying the content of the page.
Try adding this code to your sidebar.php file before $count=0;
// hold the current query results in a temp variable
$temp_query = $wp_query;
and this code
<?php
global $temp_query;
// now back to our regularly scheduled programming
$wp_query = $temp_query;
?>
after:
<?php get_a_post(29); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
Thread Starter
alfie
(@drtanz)
thanks, but still ain’t working
Sidebar.php
<div id="sidebar">
<div id="sidebar-top"></div>
<h2>Latest News</h2>
<?php
// hold the current query results in a temp variable
$temp_query = $wp_query;
$count=0;
$posts_per_page=2;
query_posts('cat=3&posts_per_page='. $posts_per_page ); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h3><?php the_title(); ?></h3>
<p><?php the_content(); ?></p>
<?php
$count++;
if ($count < $posts_per_page) { ?>
<div class="hr"><hr /></div>
<?php } ?>
<?php endwhile; endif; ?>
<?php get_a_post(25); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php get_a_post(29); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php
global $temp_query;
// now back to our regularly scheduled programming
$wp_query = $temp_query;
?>
<div id="sidebar-bottom"></div>
</div> <!-- sidebar -->
Page.php
<?php get_header(); ?>
<div id="content">
<?php get_sidebar(); ?>
<div id="content-main">
<div class="content-box">
<div class="content-box-top"></div>
<div class="content-box-middle">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="content-box-middle-gradient">
<?php the_content(); ?>
</div> <!-- content-box-middle-gradient -->
<?php endwhile; endif; ?>
</div> <!-- content-box-middle -->
<div class="content-box-bottom"></div>
</div> <!-- content-box -->
</div> <!-- content-main -->
</div> <!-- content -->
<?php get_footer(); ?>
Thread Starter
alfie
(@drtanz)
i’m also noticing that if i switch the sidebar to come after the main content column, it works. obviously however it displays the sidebar to the right of the main content column, whereas I want it to display to the left of the main content.
Anyone help me out please? this is probably a loop issue, but I don’t know so much yet to be able to troubleshoot it.
thanks
This is the page.php that works but displays the sidebar on the other side from where i want it to go.
<?php get_header(); ?>
<div id="content">
<div id="content-main">
<div class="content-box">
<div class="content-box-top"></div>
<div class="content-box-middle">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="content-box-middle-gradient">
<?php the_content(); ?>
</div> <!-- content-box-middle-gradient -->
<?php endwhile; endif; ?>
</div> <!-- content-box-middle -->
<div class="content-box-bottom"></div>
</div> <!-- content-box -->
</div> <!-- content-main -->
<?php get_sidebar(); ?>
</div> <!-- content -->
<?php get_footer(); ?>
Thread Starter
alfie
(@drtanz)
i’ve also put the site online for anyone who wishes to examine it
http://tinyurl.com/ykjpglz
try this in your sidebar.php:
<div id="sidebar">
<div id="sidebar-top"></div>
<h2>Latest News</h2>
<?php
$count=0;
// number of posts to show
$posts_to_show=2;
$sidebar_query = new WP_Query('cat=3&showposts='. $posts_to_show);
while($sidebar_query->have_posts()) : $sidebar_query->the_post();
?>
<h3><?php the_title(); ?></h3>
<p><?php the_content(); ?></p>
<?php
$count++;
if ($count < $posts_to_show) : ?>
<div class="hr"><hr /></div>
<?php endif; ?>
<?php endwhile; ?>
<?php
// ids of the posts to show
$ids_to_show=array(25,29);
$single_query = new WP_Query(array('post__in' =>$ids_to_show));
while($single_query->have_posts()) : $single_query->the_post();
?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php endwhile; ?>
<div id="sidebar-bottom"></div>
</div> <!-- sidebar -->
Great; can you mark this tread as resolved?