[resolved] Load same sidebar multiple times (4 posts)

  1. Mike Kohn
    Posted 6 years ago #

    Is there a way to load the same sidebar multiple times on a page, such as each time the loop iterates?

    I'd like to display each posts' meta data next to that post. Right now I have the info displaying just fine, but it's hard-coded in at least 4 different places (index, archive, single & category). It would be nice if I could just include a single file, i.e. a sidebar, so that making small changes would be less annoying. Right now when I use get_sidebar(), it only loads for the first post in the loop. I have also tried a general php include, but then none of the wordpress functions like get_the_time() work.

    Thanks in advance for the help!

  2. xdesi
    Posted 6 years ago #

    You could just use a simple PHP include

    <?php include('bloginfo(stylesheet_directory)/nameoffile.php') ?>

    Then you have nameoffile.php inside your themes folder in your loop, and it's contents will be included in the page? Is this what you were after?

  3. Mike Kohn
    Posted 6 years ago #

    Hey, it worked!

    I tried that before with an absolute path to the sidebar file and it resulted in a fatal error saying the function get_the_time didn't exist. But using a relative path worked.

    <?php include('sidebar.php') ?>

    Thanks for the help, xdesi!

  4. xdesi
    Posted 6 years ago #

    No probs :)

Topic Closed

This topic has been closed to new replies.

About this Topic