WordPress.org

Ready to get started?Download WordPress

Forums

Sidebar on a Separate page! (31 posts)

  1. Justin Tadlock
    Member
    Posted 9 years ago #

    I've been looking through the forums for a simple answer to this, and I just couldn't find it. First off, I've had a website for quite sometime, and I don't want to completely change all of the content over to wordpress. I basically just want to use wordpress to blog. What I want to do is take the sidebar and pull it into another page outside of the /wordpress directory. I would like the sidebar to be included with my pre-existing menu. I've tried:
    <? include(".../sidebar.php"); ?>
    but it doesn't seem to work. I have all the directories correct and everything. I'm not particularly skilled at php, but I can usually get what I want done. This seems to be bugging me though. I would greatly appreciate any help. And I can provide any other information that may be needed to help.

  2. yami
    Member
    Posted 9 years ago #

    When you say it doesn't work - does it return any error messages? Does it not include the file at all, or does it just choke on parts of it? Try setting your error reporting level to E_ALL, see if it returns anything helpful.

    Also, see this thread.

  3. Justin Tadlock
    Member
    Posted 9 years ago #

    Okay, I tried the error reporting thing. If this is the correct way to do it:
    <? error_reporting(E_ALL); ?>

    Nothing shows up. And that's the same thing that was happening before.

  4. yami
    Member
    Posted 9 years ago #

    Hm. Now that I look at your include() statement a little more closely... I think you're supposed to use single quotes, not double quotes. Could that be it?

  5. Justin Tadlock
    Member
    Posted 9 years ago #

    Okay, tried the single quote thing. Nothing changed. Plus, I use "double quotes" for all of my other includes.

    Here's the code:

    <div id="navcontainer">

    <div id="lmain">
    <h3 class="main"><span>Main</span></h3>

    </div>

    <? include("http://dark-autumn.com/wordpress/wp-content/themes/default/sidebar.php"); ?>

    <? error_reporting(E_ALL); ?>

    </div>

  6. yami
    Member
    Posted 9 years ago #

    Oh, you need to set your error reporting before attempting the include, or it won't apply.

  7. somefool
    Member
    Posted 9 years ago #

    I dont think it should have http://, I think it should just be the path to the file example in my home.php I have

    include "header.php";

    if it were an absolute path it'd be

    include "/usr/home/somefool/public_html/wp13/wp-content/themes/sflwa3c/header.php";

    it should be similarly set up in your WP admin screens, under options for uploading files.

    Im pretty sure thats right.

  8. Cypher
    Member
    Posted 9 years ago #

    There is no such thing as ".../sidebar.php", there should only be two dot's.

    Try <? include ("../sidebar.php"); ?>

    Regards

  9. somefool
    Member
    Posted 9 years ago #

    Sorry, I should point out that mine is with my header file, the theory should be fine with sidebar - just in case, sorry.

  10. Justin Tadlock
    Member
    Posted 9 years ago #

    Okay. I moved the error reporting above the include. Still no errors.

    I changed the path. And now I have an alignment problem, but the sidebar isn't showing up. It's kind of like it's including the file, but the content of "sidebar.php" isn't showing up. It shows up correctly on the wordpress pages, but not here.

    Also, if I just type in the url of "...sidebar.php" nothing comes up. Just a blank page.

  11. somefool
    Member
    Posted 9 years ago #

    It might be worth mentioning that even if you get this working, if the sidebar uses WP specific calls and the page youre trying to include it in ISNT a WP page I dont think itll work.

    I think you need to add
    require(ABSPATH . 'wp-blog-header.php');
    too the top of the page (or change the path so it gets to the wp-blog-header.php file in WP.
    I think - this is certainly how I got similar things working for my gallery.

  12. Justin Tadlock
    Member
    Posted 9 years ago #

    There is no such thing as ".../sidebar.php", there should only be two dot's.

    Try <? include ("../sidebar.php"); ?>
    ---------------------------------------------------------
    I wasn't giving the actual include statement. I just didn't type out the whole path. That's what the "..." is for.

  13. somefool
    Member
    Posted 9 years ago #

    If youre using http:// I dont think thatll work.

    Remove it, refresh the page and itll pretty much tell you what the path is because itll give you a big error.

  14. Justin Tadlock
    Member
    Posted 9 years ago #

    I tried:
    <? require(ABSPATH . '/wordpress/wp-blog-header.php'); ?>
    I think that's the way to do it, right?
    And now, my whole menu has dissapeared from the page.

    If youre using http:// I dont think thatll work.
    -------------------------------------------------------------------
    I've removed the (http://).

    I'm still getting no errors.

  15. somefool
    Member
    Posted 9 years ago #

    try just

    <? include('/wordpress/wp-blog-header.php'); ?>

    and see what happens

    If you STILL dont get any errors then something odds happening as it should cry blue murder that it cant find the file.

    the require bit was from the code that WP uses, im not sure of the difference between require and include but in this case I think include is the one.

    Also, try putting some sort of text in the side bar like "XXXX--SIDEBAR--XXXX" - id suggest at the top - just so you know its getting the right file, I often use this temporarily for troubleshooting.

  16. yami
    Member
    Posted 9 years ago #

    Includes through http should work - have you tried this with other files? Can you successfully include a plain text file from your theme directory using this method?

  17. Justin Tadlock
    Member
    Posted 9 years ago #

    somefool, You are a genious! It works! I owe you big time! Maybe I should give you a link on my page or something.
    And thanks, everyone else for helping.
    Now all I gotta do is go make it look neat and organized.

  18. somefool
    Member
    Posted 9 years ago #

    Do they? OK, Id only every got errors trying that (I think) and of course if urls change (like youre domain) it doesnt work

  19. yami
    Member
    Posted 9 years ago #

    Somefool: the difference between include and require is how they deal if they can't find the file. Include just gives a warning, require halts processing of the page and screams bloody murder.

  20. Justin Tadlock
    Member
    Posted 9 years ago #

    I wanted to include the code required to do this, in case anyone else has this problem. This is exactly how it is in my php file:

    <? error_reporting(E_ALL); ?>
    <? include('/wordpress/wp-blog-header.php'); ?>
    <? include("/wordpress/wp-content/themes/default/sidebar.php"); ?>

    Yami, I never really understood the difference between the include and require thing.

  21. somefool
    Member
    Posted 9 years ago #

    I knew it was something like that (stands to reason) as I said, I tend to use include for my theme.

    Id go with Yami's suggestion of including a simple text file and see what happens. sounds like odd things are up.

    Or are you saying it works now?

  22. Justin Tadlock
    Member
    Posted 9 years ago #

    Yeah, it works now. It worked with "include" but not with "require." Which is weird. I've never really used "require" either. I've always used "include" to get files.

  23. somefool
    Member
    Posted 9 years ago #

    cool, must have been the wp-blog-header.php bit then, that basically makes the page a 'WP Page'.

  24. Justin Tadlock
    Member
    Posted 9 years ago #

    Yeah, it was the 'wp-blog-header.php'. At least I learned something new today, and didn't give up on wordpress before I really got started with it.

  25. yami
    Member
    Posted 9 years ago #

    Hoorah for things working!

    To try and put this a little more coherently: include and require are the same function. They act in exactly the same way, except for when they can't find the file they're looking for. With include('/wrong/filename');, that file will simply be skipped and the rest of the page will be displayed without it. With require('/wrong/filename');, the PHP processor will stop trying to execute the file, and you'll see something like "Fatal Error: can't find file wrong/filename on line 236 of blah.php".

    So you should be able to change include('/wordpress/wp-blog-header.php'); to require('/wordpress/wp-blog-header.php'); and not notice any difference. Or at least, that's what the php manual says! I'm always reluctant to fiddle with these things once they're working ;)

  26. Justin Tadlock
    Member
    Posted 9 years ago #

    Yami, It works with 'require' now. Maybe the first time around, the page didn't refresh right or something. Occasionally, I have a problem when changing things on my site, they don't immediately work.

    Thanks for the info on 'require' and 'include.'

  27. somefool
    Member
    Posted 9 years ago #

    I THINK (again with the 'think' because im not too sure on this) the wp-blog-header line should be the first line of the page due to what wp-blog-header does.
    If yours isnt then clearly im wrong ;-)

  28. somefool
    Member
    Posted 9 years ago #

    You can now use WP and WP plugin calls on that page, like recent posts and even use the loop on that page to bring up posts.

    Oooo the power of WP.

  29. Justin Tadlock
    Member
    Posted 9 years ago #

    It's not the first line.
    I have:
    -site header
    -index
    -menu (with error reporting, header, and sidebar)
    -site footer

    I have many other lines of code before the 'wp-blog-header' line, and it's working fine. It probably would be best to include the 'wp-blog-header' file in the header of my site though. Just in case I want to use it for something else later on.

    <STRONG>EDIT:</STRONG> Okay, bad idea. I didn't work correctly in the 'site header' file. I had to put it back into the 'menu' file.

  30. Justin Tadlock
    Member
    Posted 9 years ago #

    You can now use WP and WP plugin calls on that page, like recent posts and even use the loop on that page to bring up posts.

    Oooo the power of WP.

    I'll have to look into all of that. I can probably do some really neat things now, with that file included

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.