Ok, this is getting closer and closer. I used some code from the website and changed a few things around. I’m still alittle confused though.
I went and renamed the file to “category-3.php” and put the following inside as well…
<?php
/*
Template Name: category-3.php
*/
?>
<?php get_header(); ?>
<?php get_sidebar(); ?>
<div id="content" class="widecolumn">
<ul>
<?php
$myposts = get_posts('category=3');
foreach($myposts as $post) :
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> --- <?php the_excerpt(); ?></li>
<?php endforeach; ?>
</ul>
Do I need to query the database before I start this loop? Is that why this is working?
<!-- Start the Loop. -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- Display the Title as a link to the Post's permalink. -->
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<!-- Display the Time. -->
<small><?php the_time('F jS, Y'); ?></small>
<!-- Display the Post's Content in a div box. -->
<?php the_content(); ?>
<!-- Display a comma separated list of the Post's Categories. -->
<p class="postmetadata">Posted in <?php the_category(', '); ?>
</div> <!-- closes the first div box -->
<!-- Stop The Loop (but note the "else:" - see next line). -->
<?php endwhile; else: ?>
<!-- The very first "if" tested to see if there were any Posts to -->
<!-- display. This "else" part tells what do if there weren't any. -->
Sorry, no posts matched your criteria.
<!-- REALLY stop The Loop. -->
<?php endif; ?>
</div>
<?php get_footer(); ?>
It looks really close (sample output to follow):
* smelly chicken —
* Gross chicken —
Recipies
May 3rd, 2007
Posted in Uncategorized
I just want the smelly chicken and the gross chicken to come after the Recipies header.
Well I nearly have it working, the only problem I am no having is the formatting. It correctly pulls the posts that are of the category “Recipies” and displays them on the page “Recipies”
The only annoying thing is that they are below the sidebar. Thanks for the help, maybe this code will help someone else do this.
<?php
/*
Template Name: category-3.php
*/
?>
<?php get_header(); ?>
<?php get_sidebar(); ?>
<div id="content" class="widecolumn">
<!-- Start the Loop. -->
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div class="post">
<?php
$myposts = get_posts('category=3');
foreach($myposts as $post) :
?>
<h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
<small><?php the_time('l, F jS, Y') ?></small>
<div class="entry">
<?php the_content() ?>
</div>
<p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
</div>
<?php endforeach; ?>
<!-- Stop The Loop (but note the "else:" - see next line). -->
<?php endwhile; else: ?>
<!-- The very first "if" tested to see if there were any Posts to -->
<!-- display. This "else" part tells what do if there weren't any. -->
Sorry, no posts matched your criteria.
<!-- REALLY stop The Loop. -->
<?php endif; ?>
<?php get_footer(); ?>
I went and renamed the file to “category-3.php” and put the following inside as well…
Why can’t you work with the category templates? Just trying to understand why all this struggle for someting that is built in WP?
I can’t make the examples work. If you know how to do what I am trying to accomplish, why not post the solution or point me to an example that will work?
The reason I am going through a struggle, is because I am trying make something work based on the web examples. Maybe you can make them better, so people like me would understand them.
Did you click on the link I gave above (before posting back)? Did you read it?
Category templates do exactly what you are trying to do: display only posts from one category and you can even style them as you wish.
So, my question was: what is different in what you are trying? Why do you need to re-invent the wheel?
(maybe I misread your posts but I couldn’t figure out what are you doing besides displaying posts by category. Not to mention – you don’t even need a category template, WP displays ONLY posts from one category when clicked its name…)
If my assumption is correct, you went wrong by creating the Page at the very beginning. No need for that.