Display the posts of one category in a Page SOLVED !!
-
After a day of reading posts that just confused me more, I finally worked out a simple solution to this common yet unsolved query.
The code (coughs politely..)
<?php
query_posts(‘cat=1’);
while (have_posts()) : the_post();
the_content();
endwhile;
?>and that’s it! You change the category number to whatever you like by changing (‘cat=1’) to whatever cat number you want. I think you can also change cat=1 to catname=boats’n’hoes but I am not sure. You will have to look that up. I got this code from the docs page : https://codex.www.ads-software.com/The_Loop under the heading loop examples. Their example is long and uncommon in my opinion so I striped out the bits i need.
NOW..to implement this code, make a template page (copy pages.php and rip out it’s content but leave the generic stuff like get_sidebar etc), and put this code (above) bang in the center.
Then..write
<?php /* Template Name: Boats’n’Hoes */ ?>
at the top of the page before anything else.Then save template page as boatsnhoes.php and put it in the same place pages.php was located.
An example of my page is as follows :
<?php
/*
Template Name: Boats’n’Hoes
*/
?>
<?php get_header(); ?>
<div id=”main”>
<div id=”content” class=”narrowcolumn”><?php
query_posts(‘cat=1’);
while (have_posts()) : the_post();
the_content();
endwhile;
?></div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>cool ? That’s it. Search no longer. High 5 !
- The topic ‘Display the posts of one category in a Page SOLVED !!’ is closed to new replies.