Forum | Fixing category pages to look like home pages

You must be logged in to post Login

Fixing category pages to look like home pages

UserPost

11:12 pm
February 11, 2010


CMLife

Member

posts 16

Hey guys,

Perhaps this question has been asked before; I apologize if it has.

I'm interested in making my sub-category pages (i.e. cm-life.com/sports) look like the Home page, but with only sports posts. Right now, if you go to cm-life.com/sports, it's basically a blogroll of the latest posts. I want the home page look to it, featured slider and all.

The part I DO know how to do is give it the home page look – by making new category-xx.php's to correspond with the particular category and copying/pasting the home page code instead of a category list. What I DON'T know how to do is make it show ONLY sports posts. Anybody know what coding I would have to throw in to make this happen?

Thanks!

-Brian Manzullo

11:28 am
February 12, 2010


Daniel Bachhuber

Admin

posts 102

Excellent question, and it's coincidental that I was just working on something like this.

The way that WordPress displays content on a page is by using something they call The Loop. Normally the loop displays the most recently published posts. What you want to do, however, is limit those recently published posts to a particular category. The way that you'll do this is by creating a new query object like this:


$recent = new WP_Query("cat=XX&showposts=YY");

Add your category number where 'XX' appears and the number of posts you want to load where 'YY' appears. You can then loop through those posts with the same style loop as you had before, only this time it's using your new set of data:


while($recent->have_posts()) : $recent->the_post();

Does that help out?

5:48 pm
February 13, 2010


CMLife

Member

posts 16

Daniel,

Thanks for the response. I seem to have that part of it working for the blog posts, but there's two problems so far (Forgive me for now having photos at the moment, I can get those up later):

1) The featured slider is not showing featured posts under a particular category. I tried inputting code and the slider just comes up black. By looking at this line, it looks like there's a place to input a category, but it doesn't work when I try it:

$the_query = new WP_Query('cat=' . $ex_feat . '&showposts=' . $featposts . '&orderby=post_date&order=desc');

Anything I'm doing wrong, by chance, or should I try the code you gave me, Daniel?

2) The formatting isn't coming up right – div class "col1″ is going all the way across the page instead of staying on the left side. So the sidebar is showing up below everything. Not sure why this is happening, I can toy with this a little bit more and see if there's a problem.

Thanks for the help, I appreciate it!


About the CoPress forum

Most Users Ever Online:

119


Currently Online:

6 Guests

Forum Stats:

Groups: 1

Forums: 7

Topics: 107

Posts: 538

Membership:

There are 151 Members

There have been 2 Guests

There are 5 Admins

There is 1 Moderator

Top Posters:

Chris Ullyott – 66

Mo Jangda – 35

arobinsonwku – 32

laurenmichell – 21

CMLife – 16

sbressler – 15

Administrators: Daniel Bachhuber (102 Posts), William P. Davis (65 Posts), joey (39 Posts), Greg Linch (14 Posts), adam (1 Post)

Moderators: Andrew Spittle (49 Posts)