Question about includes

Discussion in 'Web Design and Development' started by sbryan, Sep 28, 2009.

  1. sbryan macrumors member

    Joined:
    Jun 6, 2007
    #1
    So I'm trying to create a dynamic, editable sidebar in Wordpress and I can do it through a secondary loop.

    However, because Wordpress creates pages like www.mysite.com/pagename, I'm not sure how to include the sidebar: www.mysite.com/sidebar through PHP or HTML.

    Any ideas? Thanks guys.
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    If I'm understanding you, this is my solution. Use the server variable to get the root of your site, then give the path to the page. WordPress also has some variables for this I believe.
    PHP:
    include $_SERVER['DOCUMENT_ROOT'] . '/path2/page.php';
     
  3. sbryan thread starter macrumors member

    Joined:
    Jun 6, 2007
    #3
    Angelwatt, I did give that a try, but because I'm referencing the php document out-of-the-loop, it's not grabbing the information I want.

    There may be another way besides creating a page in Wordpress, which I'm trying to do currently, but there seems to be no information on creating a dynamic (editable) sidebar.

    Frustrating! Thanks for the reply.
     
  4. brisbaneguy29 macrumors 6502

    brisbaneguy29

    Joined:
    Nov 27, 2007
    Location:
    Brisbane
    #4
    First you need to set your functions.php file to register the 2 sidebars. If you don't have one, create a functions.php file and put it in your theme folder.
    PHP:
    <?php
    if ( function_exists('register_sidebars') )
    register_sidebars(2);
    ?>
    Then create a second sidebar PHP file, call it sidebar2.php. To inset the second sidebar use
    PHP:
    <?php include (TEMPLATEPATH '/sidebar2.php'); ?>
    You can use this to include any number of sidebars, and can have different pages with different sidebars, showing different information. Doing it this way will allow you to edit the sidebars in the admin through Widgets.
     

Share This Page