Support » Plugin: Custom Sidebars - Dynamic Sidebar Widget Area Manager » Show sidebars based on chosen categories for pages as well

  • Resolved Jan Weiss

    (@rumpel2116)


    Hi there,

    I’m using a simple plugin to extend the category -and tag functionality for pages: https://wordpress.org/plugins/post-tags-and-categories-for-pages/
    It allows to use the stock category functionality with pages, nothing more.

    Having categories added to a few pages I would like to use custom sidebars with those categories: Show a custom sidebar based on pages, based on which category the page has.
    I would guess that the only reason it doesn’t work is that you don’t search pages for categories, just posts. Usually (I have that problem with a few plugins), I just add ‘page’ to post types to search and it works perfectly fine.
    But here I didn’t find the position I could try adding it – could you help me add pages to be included when looking if a custom sidebar should be displayed based on its category?

    Thanks,
    Jan

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter Jan Weiss

    (@rumpel2116)

    Well, sometimes I just don’t look long enough…
    I found the file and code at /inc/class-custom-sidebars-replacer.php around lines 200-400.
    For posts (is_single()) you go through 4 steps, 1.1 to 1.4, lines 208 to 277. Step 1.3 checks for categories.
    For pages, on step 5, it’s only 3 steps, excluding the category one (lines 361 to 426). The rest is fairly similar to the posts. I now just copied step 1.3 and pasted it as ‘5.25 CUSTOM’ in between 5.2 and 5.3 and it all works!

    I still got a little help request though: How do I store those changes save now; without getting replaced with your next plugin update?
    Thanks for your help!

    The copied code:

    			// 5.25 CUSTOM If no metadata set then use the category settings.
    			if ( $replacements_todo > 0 ) {
    				$categories = self::get_sorted_categories();
    				$ind = sizeof( $categories ) -1;
    				while ( $replacements_todo > 0 && $ind >= 0 ) {
    					$cat_id = $categories[ $ind ]->cat_ID;
    					foreach ( $sidebars as $sb_id ) {
    						if ( $replacements[ $sb_id ] ) { continue; }
    						if ( ! empty( $options['category_single'][ $cat_id ][ $sb_id ] ) ) {
    							$replacements[ $sb_id ] = array(
    								$options['category_single'][ $cat_id ][ $sb_id ],
    								'category_single',
    								$sidebar_category,
    							);
    							$replacements_todo -= 1;
    						}
    					}
    					$ind -= 1;
    				}
    			}

    Hi Jan,

    Hope you’re doing well šŸ™‚

    Glad to see you’ve managed to find a solution.

    However, I’m afraid that there’s no workaround for this without actually modifying the plugin core files.
    I will forward these nice steps that you provided to our devs so they can check it out and see if it’s something that could be added in future versions of the plugin.

    Cheers,
    Predrag

    Thread Starter Jan Weiss

    (@rumpel2116)

    Hi Predag,

    alright, I wont update the plugin then. Or copy it in there again manually.
    Do you think you could update me (here or per email) if you integrate the functionality?

    Thanks,
    Jan

    Hey @rumpel2116,

    Hope you’re well.

    We can update this thread if we add this feature to next updates, I am adding notes about that into the report that Predrag created. But until that time if you want to use it you should continue with your own custom codes. Unfortunately, there is no feature in WordPress that can save your custom changes at plugin updates. You need to do same custom implementations when plugin updated.

    Cheers,
    Oguz

    Just to say that this is exactly what I am looking for as well.

    Thread Starter Jan Weiss

    (@rumpel2116)

    Hi there!
    Any news on this one? I fear I will update it sometime because I forget about the custom code… Just those few line changes provided, please šŸ™‚

    Thanks,
    Jan

    Hey @rumpel2116,

    Hope you’re well.

    I am afraid it’s not published yet. But we are in the testing phase for that, so it will be included soon. Thanks for your patience!

    Cheers,
    Oguz

    Thread Starter Jan Weiss

    (@rumpel2116)

    You fixed this with the latest update (3.2.0), thanks a lot! Works perfectly.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Show sidebars based on chosen categories for pages as well’ is closed to new replies.