Support » Fixing WordPress » Why won't this query_posts work?

  • Resolved ransom1337

    (@ransom1337)


    Hello,

    I’m trying to display an excerpt of the most recent blog post on the home page of my website. I’m doing this by putting this code at the top of the index.php:

    <?php
    // Include WordPress
    define('WP_USE_THEMES', false);
    require('http://www.url.com/blog/wp-load.php');
    query_posts('showposts=1');
    ?>

    When loading up index.php I get the error:

    Fatal error: Call to undefined function query_posts() in /home1/chrisayr/public_html/projects/callumtoy/index.php on line 5

    This code works when I have my index.php page at http://www.url.com, but if I put it in my desired location (www.url.com/projects/imac/index.php) then this problem occurs. Anyone know why this is, and how I can get around it?

    Thank you.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I don’t think you use urls in requires or includes, you use paths, either relative or absolute

    so maybe….

    <?php
    // Include WordPress
    define('WP_USE_THEMES', false);
    require('/home1/chrisayr/public_html/blog/wp-load.php');
    query_posts('showposts=1');
    ?>

    or

    <?php
    // Include WordPress
    define('WP_USE_THEMES', false);
    require('../../blog/wp-load.php');
    query_posts('showposts=1');
    ?>

    Have you tried:

    require('/home1/chrisayr/public_html/blog/wp-load.php');

    [edit well the good Rev got there first]

    Brilliant, that worked nicely. Still new to PHP, thanks for your help guys 🙂

    [edit well the good Rev got there first]

    lol….always good to have a second opinion, as I’m just going off my miniscule amount of knowledge, mixed with google!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Why won't this query_posts work?’ is closed to new replies.