0

I've made an option of creating unlimited sidebars, then there is an option to select any desired sidebar from a select element, which is a custom meta field, in each category edit page. So far so good, everything works and every category displays the selected sidebar.

Now what i am trying to do is to output the same sidebar in every post (single.php) as in the category this post is assigned to.

Have anyone done something similar?

The code for outputting the sidebar in category page is:

<?php
if ( is_category() ){
   $sidebar = get_post_meta( $post->ID, 'select_a_sidebar', true );
   dynamic_sidebar( $sidebar );
}
?>
  • 1
    Without knowing how your existing code works, how can we guess at how to extend it? – s_ha_dum May 25 '14 at 13:28
  • Just added the code. – Vasili May 25 '14 at 13:39
0

Retrieving category post is assigned to is rather straightforward with get_the_category(). However note that post can be easily placed into multiple categories and you will need some (quite elaborate) logic if you want to apply any particular sorting logic to it.

From looking at your code however it's not clear how exactly category/post/sidebar are tied to each other since you are retreiving sidebar info from post alone.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.