Web Hosting Talk







View Full Version : Wordpress - Category Question


Biju
03-03-2008, 11:20 AM
Friends,

I was just doing some coding in PHP, i am struck in a part. Can anyone state me whats the problem....

<?php

$category = get_the_category();
$recent = new WP_Query("cat='echo $category[0]->cat_ID;'&showposts=1"); while($recent->have_posts()) : $recent->the_post();

?>

I want to show one post from the particular category if visited. This particular code works but displays the recent post.

If i place cat = 43 or something it works perfectly. My Question is

Why is echo $category[0]->cat_ID; not printing out the ID number dynamically based on the category.

Note : I am not a PHP programmer. I am a JAVA. :D

Regards

foobic
03-03-2008, 06:17 PM
Why is echo $category[0]->cat_ID; not printing out the ID number dynamically based on the category.Because you're trying to run the echo command inside a quoted string. But you don't want it printed out anyway, you want to pass it as a parameter. Try this:
$recent = new WP_Query("cat=" . $category[0]->cat_ID . "&showposts=1");