Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2004
    Location
    Chennai , India
    Posts
    4,608

    Wordpress - Category Question

    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.

    Regards

  2. #2
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    Quote Originally Posted by Biju View Post
    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:
    PHP Code:
    $recent = new WP_Query("cat=" $category[0]->cat_ID "&showposts=1"); 
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •