WordPress.org

Forums

[resolved] Why won't this query_posts work? (5 posts)

  1. ransom1337
    Member
    Posted 4 years ago #

    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.

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    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');
    ?>
  3. MichaelH
    Member
    Posted 4 years ago #

    Have you tried:

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

    [edit well the good Rev got there first]

  4. ransom1337
    Member
    Posted 4 years ago #

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

  5. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

    [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!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.