Results 1 to 5 of 5

 

Thread: Easy PHP challenge

  1. #1
    CompareStorePrices.co.uk

    Status
    Offline
    Join Date
    Aug 2003
    Location
    Sussex
    Posts
    649
    Thanks
    4
    Thanked 5 Times in 4 Posts


    OK I am a windows programmer and am trying to get my head around the basics of PHP so I can make a few changes to Wordpress blogs.

    I am pulling my hair out with the following as it doesn't work and just gives me a blank page:

    <?php $title = wp_title(); ?>

    <?php if (empty($title)) ?>

    some html

    <?php else : ?>

    some html

    <?php endif; ?>

    I'm sure it's a syntactical error?

    If anyone can let me know what I am doing wrong it would be much appreciated :-)
    Chris Young


  2. #2
    Typing with both fingers.

    Status
    Offline
    Join Date
    Aug 2003
    Location
    Allt Y Coed Farm, North Pembrokeshire
    Posts
    4,123
    Thanks
    247
    Thanked 198 Times in 157 Posts
    I'd do this :-


    PHP Code:

    <?php $title wp_title(); ?>

    <?php if (empty($title)) { ?>

    some html

    <?php } else {  ?>

    some html

    <?php }  ?>
    Ta

    Barry

  3. #3
    CompareStorePrices.co.uk

    Status
    Offline
    Join Date
    Aug 2003
    Location
    Sussex
    Posts
    649
    Thanks
    4
    Thanked 5 Times in 4 Posts
    Thanks Barry - that has to take the record for the quickest answer ever!
    Chris Young


  4. #4
    Typing with both fingers.

    Status
    Offline
    Join Date
    Aug 2003
    Location
    Allt Y Coed Farm, North Pembrokeshire
    Posts
    4,123
    Thanks
    247
    Thanked 198 Times in 157 Posts
    No problems

    Ta

    Baz

  5. #5
    Registered User

    Status
    Offline
    Join Date
    Jun 2008
    Location
    Manchester
    Posts
    8
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by CompareStore View Post

    <?php if (empty($title)) ?>
    Barry's answer works but to fix your problem you were just missing a colon after the last bracket:

    <?php if (empty($title)) : ?>

    It's just the alternate syntax for the curly brackets:

    if ( blah )
    {
    // Your code
    }

    or

    if ( blah ) :
    // Your code
    endif;

    I'm from a C/C++ background and I prefer the former but it's easier to use the latter when combining it with HTML.

    Cheers,
    Marc



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. PaddyPower MBS- Easy Ryder - Easy Money!
    By dganly in forum Casino, Bingo & Gaming
    Replies: 1
    Last Post: 03-01-09, 03:23 AM
  2. DVD Challenge
    By channel5 in forum Affiliate Marketing Lounge
    Replies: 3
    Last Post: 17-12-08, 02:59 PM

Bookmarks

Posting Permissions

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

Content Relevant URLs by vBSEO 3.5.0 RC2