WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Extracting from the loop, CMS site etc. (7 posts)

  1. AndySpeed
    Member
    Posted 8 years ago #

    Not necessarily looking for a direct answer (but if yo got one please do!)

    Using wordpress as a CMS system for my site. But due to the nature of it being a site, I've re-written certain pages in normal php and html and taken things out of 'the loop'.

    What I want to do is include the latest blog posts on a php sidebar file that is outside the loop and standalone called sidebar2.php

    Now as the file will be out of the loop I'm assuming certain 'calls' for information won't work. I've already done a few tests and am overwhelmed with error messages.

    In short:

    A standalone sidebar file located in a totally different directory to wordpress wishes to get certain snippets of information from it.

    Any useful links or codes? (I wish to learn for myself as much as possible)

    Don't link these, I've read them:
    http://codex.wordpress.org/Templates
    http://codex.wordpress.org/The_Loop_in_Action

  2. moshu
    Member
    Posted 8 years ago #

    You can use any WP function in files outside of the WP folder, if:
    the files have at the top (before anything else) this
    <?php
    require('./path-to-your-blog/wp-blog-header.php');
    ?>

    [replace it with your path, of course]

    Now, if you want those posts in that sidebar2.php... I wouldn't try to put the above code in the sidebar file, but in the file that will include sidebar2.php.
    WARNING: I am not a coder, so don't quote me :)

  3. AndySpeed
    Member
    Posted 8 years ago #

    Oh thats a beaut moshu!

    I now need to undo some of the things I did to try and do things my own way but already things are working which didn't before.

    Appreciated

    (I'll change the topic status to resolved soon but not quite yet ;) )

  4. AndySpeed
    Member
    Posted 8 years ago #

    Ok back to the topic

    Similar issue

    I've got a file located in a different directory to wordpress.

    For example, wordpress is installed in the root directory, and i have another file in folders called /circuits/snetterton/ from the same root directory.

    The code moshu has given me does not seem to work for this particular file.:

    Fatal error: Call to undefined function: get_header

    Reason I'm using directories in this manner is to allow for logical organisation and linking for my site.

  5. AndySpeed
    Member
    Posted 8 years ago #

    Any help here folks?

  6. AndySpeed
    Member
    Posted 8 years ago #

    Is it possible to resolve my problem?

    Yes/No then the topic can be left.

  7. moshu
    Member
    Posted 8 years ago #

    Probably the path is not correct. Only YOU can resolve it by putting the correct path in the code line.

Topic Closed

This topic has been closed to new replies.

About this Topic