Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 2344 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

Wordpress Issue

Thread title: Wordpress Issue
Reply    
    Thread tools Search this thread Display Modes  
10-03-2009, 03:16 AM
#1
launchplanet is offline launchplanet
Status: I'm new around here
Join date: Dec 2008
Location:
Expertise:
Software:
 
Posts: 16
iTrader: 0 / 0%
 

launchplanet is on a distinguished road

  Old  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

Reply With Quote
10-03-2009, 05:25 AM
#2
Jordan is offline Jordan
Jordan's Avatar
Status: #pugs {display: block;}
Join date: Jan 2007
Location: Chicago
Expertise: CSS, HTML, PHP
Software: Sublime Text 2
 
Posts: 1,187
iTrader: 7 / 100%
 

Jordan is on a distinguished road

  Old

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?

Reply With Quote
10-03-2009, 12:44 PM
#3
spencerp is offline spencerp
Status: On Vacation
Join date: Apr 2007
Location: Milton, Pennsylvania, USA
Expertise:
Software:
 
Posts: 1,332
iTrader: 27 / 100%
 

spencerp is an unknown quantity at this point

Send a message via AIM to spencerp Send a message via MSN to spencerp Send a message via Yahoo to spencerp

  Old

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

Reply With Quote
10-03-2009, 02:26 PM
#4
Gaz is offline Gaz
Gaz's Avatar
Status: Request a custom title
Join date: Apr 2007
Location: UK
Expertise: Code & Programming
Software: Coda, TextMate, Sublime 2
 
Posts: 2,097
iTrader: 26 / 100%
 

Gaz will become famous soon enough Gaz will become famous soon enough

Send a message via Skype™ to Gaz

  Old

Originally Posted by spencerp View Post
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).

Reply With Quote
10-03-2009, 02:32 PM
#5
spencerp is offline spencerp
Status: On Vacation
Join date: Apr 2007
Location: Milton, Pennsylvania, USA
Expertise:
Software:
 
Posts: 1,332
iTrader: 27 / 100%
 

spencerp is an unknown quantity at this point

Send a message via AIM to spencerp Send a message via MSN to spencerp Send a message via Yahoo to spencerp

  Old

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.'

Reply With Quote
10-03-2009, 07:59 PM
#6
Jordan is offline Jordan
Jordan's Avatar
Status: #pugs {display: block;}
Join date: Jan 2007
Location: Chicago
Expertise: CSS, HTML, PHP
Software: Sublime Text 2
 
Posts: 1,187
iTrader: 7 / 100%
 

Jordan is on a distinguished road

  Old

@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.

Reply With Quote
10-04-2009, 07:34 PM
#7
spencerp is offline spencerp
Status: On Vacation
Join date: Apr 2007
Location: Milton, Pennsylvania, USA
Expertise:
Software:
 
Posts: 1,332
iTrader: 27 / 100%
 

spencerp is an unknown quantity at this point

Send a message via AIM to spencerp Send a message via MSN to spencerp Send a message via Yahoo to spencerp

  Old

@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.

Reply With Quote
10-04-2009, 08:26 PM
#8
Jordan is offline Jordan
Jordan's Avatar
Status: #pugs {display: block;}
Join date: Jan 2007
Location: Chicago
Expertise: CSS, HTML, PHP
Software: Sublime Text 2
 
Posts: 1,187
iTrader: 7 / 100%
 

Jordan is on a distinguished road

  Old

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.

Reply With Quote
10-04-2009, 08:29 PM
#9
spencerp is offline spencerp
Status: On Vacation
Join date: Apr 2007
Location: Milton, Pennsylvania, USA
Expertise:
Software:
 
Posts: 1,332
iTrader: 27 / 100%
 

spencerp is an unknown quantity at this point

Send a message via AIM to spencerp Send a message via MSN to spencerp Send a message via Yahoo to spencerp

  Old

Oh I totally agree! I hate using too many plugins, and if I can or could find a way, I'll just put most of the important code in functions.php file, then I'm good to go! LOL! But yep, when I was moderator on their wordpress.org/support board years ago... Codex was always the place I went first... I even went there first, when I basically stopped going to their support forum... But Google was second choice though too...

Reply With Quote
Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed