drewshen
Member
Posted 3 years ago #
Hello, I created a page template in order to display a certain category in my blog.
<?php query_posts('cat=5'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); // the loop ?>
The query_posts line is what I added to my page template file, the category's id being 5. However, when I go to the page on my site, it simply displays the page title, and no data, just a blank page. Does anyone know what I am doing wrong? Thanks!
thelastknight
Member
Posted 3 years ago #
If that is your full loop, then you're missing some bits.
Below is a simple example
<?php query_posts('cat=5'); ?>
<?php while (have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; ?>
drewshen
Member
Posted 3 years ago #
Thanks for the reply! That is actually not my full loop, I merely posted those two lines to display the line of code I added for the sake of saving space. here is the full loop:
<?php query_posts('cat=5'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); // the loop ?>
<!--post title-->
<h1 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h1>
<!--post text with the read more link-->
<?php the_content(); ?>
<!--for paginate posts-->
<?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?>
<?php //comments_template(); // uncomment this if you want to include comments template ?>
<?php endwhile; // end of one post ?>
<?php else : // do not delete ?>
<h3>Page Not Found</h3>
<p>We're sorry, but the page you are looking for isn't here.</p>
<p>Try searching for the page you are looking for or using the navigation in the header or sidebar</p>
<?php endif; // do not delete ?>
thelastknight
Member
Posted 3 years ago #
Try restructuring the top two lines to -
<?php
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('cat=-5');
?>
<?php if (have_posts()) : ?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
Do you have any other loops on the page?
drewshen
Member
Posted 3 years ago #
Still no dice, this is the only loop i have on the page.
drewshen
Member
Posted 3 years ago #
http://www.alliancechristiancenter.org/development/news/events/
This is the link to the page I am trying to display the category in. I have tried even just displaying all posts on the page, but it seems as if no data is being retreived at all
Try using get_posts instead, and see if it works. I had a similar problem and used get_posts to solve it, but I had other loops on the page...
http://codex.wordpress.org/Template_Tags/get_posts