|
|
|
|
Thread title: Wordpress Issue |
|
|
|
|
|
Thread tools
Search this thread
Display Modes
|
|
10-03-2009, 03:16 AM
|
#1
|
Status: I'm new around here
Join date: Dec 2008
Location:
Expertise:
Software:
Posts: 16
|
Wordpress Issue
Hi.
I'm looking for someone to figure out why this is happening. I want my category page to display the posts in that category. Below you can view the image of the code I have. For some reason, it is displaying all of the posts, not just posts specific to that category.
Any suggestion is appreciated.
Tom
|
|
10-03-2009, 05:25 AM
|
#2
|
Status: #pugs {display: block;}
Join date: Jan 2007
Location: Chicago
Expertise: CSS, HTML, PHP
Software: Sublime Text 2
Posts: 1,187
|
Your query is set to grab 10 recent posts, not just from a specific category.
Is your category going to have a completely different design from the rest of your site? Do you NEED to show 10 posts or what is the effect you're trying to do here?
|
|
10-03-2009, 12:44 PM
|
#3
|
Status: On Vacation
Join date: Apr 2007
Location: Milton, Pennsylvania, USA
Expertise:
Software:
Posts: 1,332
|
It's generally best not to touch the loop yourself. You'll find that WordPress actually does all the magic for you. Don't create a new WP_Query object, and don't even call query_posts(). WordPress will call that for you automatically. In fact, if you don't call query_posts(), it'll let you set the number of posts to be displayed in the WP admin, which is easier than having to edit the theme file every time you want to change it.
Unless you're creating a category post listing for a sidebar or something complex, it's not necessary to create new WP_Query objects.
Read up on "The Loop" from the WordPress Codex for some really good information on the subject. Two links that might help you...
http://codex.wordpress.org/The_Loop and http://codex.wordpress.org/Template_Tags/query_posts
Cheers,
spencerp
|
|
10-03-2009, 02:26 PM
|
#4
|
Status: Request a custom title
Join date: Apr 2007
Location: UK
Expertise: Code & Programming
Software: Coda, TextMate, Sublime 2
Posts: 2,097
|
Originally Posted by spencerp
It's generally best not to touch the loop yourself. You'll find that WordPress actually does all the magic for you. Don't create a new WP_Query object, and don't even call query_posts(). WordPress will call that for you automatically. In fact, if you don't call query_posts(), it'll let you set the number of posts to be displayed in the WP admin, which is easier than having to edit the theme file every time you want to change it.
Unless you're creating a category post listing for a sidebar or something complex, it's not necessary to create new WP_Query objects.
Read up on "The Loop" from the WordPress Codex for some really good information on the subject. Two links that might help you...
http://codex.wordpress.org/The_Loop and http://codex.wordpress.org/Template_Tags/query_posts
Cheers,
spencerp
|
In fact Spencer, query posts is probably the correct way to do this, as the loop can only really be called once.
What you have at the moment should work with one tiny adjustment:
change
PHP Code:
$recent = new WP_Query("showposts=10")
to
PHP Code:
$recent = new WP_Query("cat=10")
Assuming the cat id is 10.
G.
Ps.For semantic purposes I would thus change all $recents to something like $cats so you don't get confused later on.
EDIT: Just noticed that you are doing this in category.php. If you don't need an alternate structure I would just delete the file and let WP use index.php / the default category file (archives.php).
|
|
10-03-2009, 02:32 PM
|
#5
|
Status: On Vacation
Join date: Apr 2007
Location: Milton, Pennsylvania, USA
Expertise:
Software:
Posts: 1,332
|
Okay, I just thought that querying posts, would limit the user to querying specifically. I think the OP wants to get all the posts per page, for a category though? Maybe my mind is still half a sleep though LOL! ...
But when using query function, and specifying ... the category number. They'll only get posts FROM that specified category ID number..
"I'm looking for someone to figure out why this is happening. I want my category page to display the posts in that category. Below you can view the image of the code I have. For some reason, it is displaying all of the posts, not just posts specific to that category.'
|
|
10-03-2009, 07:59 PM
|
#6
|
Status: #pugs {display: block;}
Join date: Jan 2007
Location: Chicago
Expertise: CSS, HTML, PHP
Software: Sublime Text 2
Posts: 1,187
|
@Spencer - Querying posts is great if you plan on having more than one loop or want something more than what the general loop can give you (eg: you want to exclude a cat, or you want to just query all stickied posts.. yadda yadda.)
@OP - Just style your archive.php page and your category (& tags) will adhere to that design.
|
|
10-04-2009, 07:34 PM
|
#7
|
Status: On Vacation
Join date: Apr 2007
Location: Milton, Pennsylvania, USA
Expertise:
Software:
Posts: 1,332
|
@jordanriane, Yeah, I was actually going to say to use the built-in / normal cat php file from the Default Theme or something similar. But asked a long time wordpess / php buddy of mine about what to say, since I've been out of the WordPress helping for a few years now... I guess it's one of those cases, if you don't use it/ do it, you lose it... I seriously do need to get back into WordPress related stuff again though... Thanks though jordanriane, for offering your sound advice.
|
|
10-04-2009, 08:26 PM
|
#8
|
Status: #pugs {display: block;}
Join date: Jan 2007
Location: Chicago
Expertise: CSS, HTML, PHP
Software: Sublime Text 2
Posts: 1,187
|
The biggest resource you'll ever need is the Wordpress codex; You can find anything and everything you need to know there.. 2nd best resource are blogs devoted to Wordpress itself.
My favorite thing now is not using plugins when I can use my own "plugin" in functions.php.
|
|
|
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|