Simple Basic PHP Help Required Please

Discussion in 'PHP' started by wd_2k6, Mar 3, 2008.

  1. #1
    Hi can somebody please tell me how to do the following:

    When i want to display the title in PHP I use: the_title();

    OK I have the following Code:
    <?php
    query_posts(array(
    'cat'=>'5',
    'tag_slug__and'=>array('whatever'),
    ) );?>

    How can i display the_title() instead of the 'whatever'? I try to edit it but i keep getting a php error i do not know how to replace the text 'whatever' with the variable the_title().
     
    wd_2k6, Mar 3, 2008 IP
  2. Dudleyswarehouse.com

    Dudleyswarehouse.com Banned

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    can you provide the files from where this is at?

    :)
     
    Dudleyswarehouse.com, Mar 3, 2008 IP
  3. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I am using WordPress.
    Currently this code will search for all posts with the tag football.
    'tag_slug__and'=>array('football'),
    However i need it so that it will search for all posts with a dynamic tag. The tag will be the title of the post. I just don't know how to insert it properly.
    I tried 'tag_slug__and'=>array(the_title();) but then an error come up saying it expected the ' '
    So i tried 'tag_slug__and'=>array('the_title();') but this does not work either.
     
    wd_2k6, Mar 3, 2008 IP
  4. The Critic

    The Critic Peon

    Messages:
    392
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Since 'the_title' isn't actually a variable (it's a function), try this instead.

    
    <?php
    $the_title=the_title();
    query_posts(
         array(
         'cat'=>'5',
         'tag_slug__and'=>array($the_title),
         ) 
    );
    ?>
    
    PHP:
     
    The Critic, Mar 3, 2008 IP
  5. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hmm didn't seem to work either, i just used a custom field instead. Many Thanks for your help!
     
    wd_2k6, Mar 4, 2008 IP