Using the Wordpress Loop - PHP not working?

Discussion in 'Web Design and Development' started by mariahlullaby, Oct 16, 2007.

  1. mariahlullaby macrumors 6502a

    mariahlullaby

    Joined:
    Jan 19, 2005
    Location:
    NYC
    #1
    Hi,

    Can anyone help me with this problem? I'm not a programmer by any means, so I don't know what I'm screwing up. I want to add a section on the front page of my site listing my latest blog posts. I'm following the instructions from Word Press and making sure to change the URLs in the code to reflect mine. Instead of it doing anything, I'm just getting some gross text of a portion of the code on the main page. Any thoughts?

    If you need to see it to know what I mean, just post here and I'll upload a screen cap. Thanks, guys!
     
  2. maximile macrumors member

    Joined:
    Oct 27, 2003
    Location:
    Herefordshire, UK
    #2
    Can we see the code? It could be all sorts of things.

    One thing to check for might be missed quote marks in strings. Or perhaps unescaped quote marks.

    That means, if you wanted to put this into your page:

    You couldn't do:

    PHP:
    echo 'It's cold.';
    You'd have to do one of these:

    PHP:
    echo 'It\'s cold.'// escaping the apostrophe
    echo "It's cold.";
    echo 
    'It’s cold.';
    That first method is called "escaping". The backslash isn't printed.

    Anyway, that's my guess, but it could be something completely different.
     
  3. mariahlullaby thread starter macrumors 6502a

    mariahlullaby

    Joined:
    Jan 19, 2005
    Location:
    NYC
    #3
    Thank you! For reference, I uploaded a demo of the page here: http://www.w3promotions.com/home.html

    The code is:

    PHP:
                                        <?php
    $how_many
    =3//How many posts do you want to show
    require_once("/blog/wp-config.php"); // Change this for your path to wp-config.php file ?>
    <ol id="whats-new">
    <?
    $news
    =$wpdb->get_results("SELECT `ID`,`post_title` FROM $wpdb->posts
    WHERE `post_type`=\"post\" AND `post_status`= \"publish\" ORDER BY 'ID' DESC LIMIT "
    .$how_many);
    foreach(
    $news as $np){
    print (
    "<li><a href=\"");
    echo 
    get_permalink($np->ID);
    print (
    "\">$np->post_title</a></li>");
    ?>
    </ol>
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    Make the <? into <?php. Some servers need the php added to <? to be interpreted correctly.
     
  5. mariahlullaby thread starter macrumors 6502a

    mariahlullaby

    Joined:
    Jan 19, 2005
    Location:
    NYC
    #5
    Hmmm that doesn't seem to be working either. Any other ideas? I really appreciate your help!
     
  6. maximile macrumors member

    Joined:
    Oct 27, 2003
    Location:
    Herefordshire, UK
    #6
    It seems like no PHP is being executed. That could be because the server isn't set up to recognise .html files as PHP. Perhaps you could try renaming it to home.php instead and see if that makes a difference.
     

Share This Page