Forums

Splitting sidebar code from template (4 posts)

  1. pramclub
    Member
    Posted 5 years ago #

    The theme I use is Sharepoint Like, which I downloaded fro Alex King's site (http://alexking.org/projects/wordpress/themes) and the header, footer and sidebar code is all included in the main page template.

    I haven’t upgraded to 2.1 yet, but before I do is this the time I should think about splitting the code into separate files? I’ve only been using WP for a month, so I don’t want to take on anything that’s going to cause a zillion problems. I'm experienced with HTML and some CSS, but this is my first experience with php.

    TIA

  2. Otto
    Tech Ninja
    Posted 5 years ago #

    It's easy. Take the sidebar code. Copy and paste it into a file called "sidebar.php". Where the sidebar code was, put this:
    <?php get_sidebar(); ?>

    Done and done. You can also do this with these:
    <?php get_header(); ?>
    <?php get_footer(); ?>
    to refer to header.php and footer.php, respectively.

    These three are special cases in WordPress and so have their own functions to deal with them.

  3. pramclub
    Member
    Posted 5 years ago #

    Thanks Otto - is it better to have separate files for these sections? Many templates seem to be created that way, and I'm not sure if that's a more recent method, which will become a required standard in WP eventually.

  4. Otto
    Tech Ninja
    Posted 5 years ago #

    "Better" is a relative term. I like having them separate, but some people don't. There can be pros and cons either way.

    I'd separate them, but that's just me. I like them separate to keep them clearly defined.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.