WordPress.org

Forums

Adding sidebar support (4 posts)

  1. BeornS
    Member
    Posted 11 years ago #

    My MT blog uses categories to place content in different locations on the page - the main area + a sidebar for very short entries. In MT this is easy, all I have to do is say that here I want to show only members of the main category, and here members of the sidebar category, and this works whether I'm on the default page or browsing through archives. I'm looking for ways to replicate this behavior in WP, and before I start coding I thought I'd check with people here, in case I overlook something, reinvent the wheel or make things really hard for myself when the next version comes out.
    The one thing I can't do is use get_posts in functions.php. I've added category support to it, so I _can_ ask for the last 10 posts in category sidebar, but I want to support the archives as well. If you search for entries in May 2004, I want to see all entries from that month, placed in the right location. Same if I search for the text "Norway" - show it all on one page, main area + sidebar as selected.
    What it seems to me I need to do is hack into the code that builds the SQL statement in wp-blog-header.php, (haven't found any hooks for this), and make sure that whatever it does (default page / date archive / search), it does twice, once for main area, once for sidebar. It should also support use of multiple categories. I only use those two today, but it would be dumb to close off the opportunity to, say, have a page for category "politics", where posts that are member of both "main" + "politics" are shown in the main area, and "sidebar" + "politics" in the sidebar.
    I've ended up with two alternatives. 1) Use categories to set location, as in MT. All visible posts must be member of either "main" or "sidebar", in addition to any categories that describe the content. wp-blog-header.php must more or less be run twice, and the category section changed to also require membership of category main (first time it is run) and sidebar (second time it is run), in addition to any other categories that have been selected.
    2) Leave categories to describe the content, and add something new to set the location, for instance a column "location" in the wp_posts table or a meta_key "location" in wp_postmeta. Create a plugin to add a choice of "main area" or "sidebar" to the edit post page, and the lines from where $request is set to where $posts is set (449-463) in wp-blog-header.php must be run twice, once with "AND location='1'" and once with "AND location='2'". (Or a test on meta_key/value and a join with wp_postmeta.)
    In both cases, you end up with two variables, $posts and $sidebarposts, which can be shown in the usual way.
    The first is the simplest but also the dirtiest solution, I feel. The second is cleaner, as it separates location from what categories are meant to do, describing the content, and also requires less messing around with code that will be overwritten in later versions, but I'm uncertain about how to do it, change wp_posts or use wp_postmeta? Any comments on that? Anything I've overlooked? Is there a way to do any of this that doesn't require me doing it all over again in the next version?

  2. Matt Mullenweg
    Troublemaker
    Posted 11 years ago #

    So you want the category in your archives, but not on your front page?
    if ('/' == $_SERVER['REQUEST_URI'] && !$cat) $cat = -12;

  3. BeornS
    Member
    Posted 11 years ago #

    No, I want all content everywhere to be sorted into two locations, depending on which of two location categories they're member of, independently of any additional descriptive categories. So whether you're looking at the default page, looking at a descriptive category, browsing the archive or searching for a text string, whatever has location main is shown in the main area, and whatever has location sidebar is shown in the sidebar.

  4. rayne
    Member
    Posted 11 years ago #

    Have you looked at the ShowCategories plugin: http://wordpress.org/support/10/6555? or Matt's Asides: http://wordpress.org/support/10/5606?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.