Tagged: x
-
AuthorPosts
-
February 19, 2017 at 11:24 am #1377193
JfantasyBooksParticipantHello Again!,
Details:
Name: JFantasyBooks
Site: Fantasy-Books
Site Url: https://fantasy-books.live
WordPress Version: 4.7.1
X Version: 4.6.4
Cornerstone Plugin Version: 1.33Problem:
So, I saw a thread here that could solve my problem.
I wanted to assign all the posts under a particular category the same sidebar automatically.
Only, it doesn’t work. I’ve followed the steps exactly, but the first method leaves my sidebar completely blank and my content skewed. The second method provided with the ‘cleaned’ code does nothing.
I was hoping you could help.
Can you provide exact instructions on how to allow the sidebars to show for all the posts under a specified category?
Thanks.
February 19, 2017 at 12:19 pm #1377228
RupokMemberHi there,
Would you clarify what exactly you are trying to achieve? Also it would be better if you provide your login credentials in a private reply so that we can check your setup.
Cheers!
February 19, 2017 at 5:02 pm #1377404
JfantasyBooksParticipantI use the ethos stack.
I just want to be able to apply the sidebars I create to not just one post or page, but all the posts in the category that I pick under taxonomies.
I was hoping you could provide exact instructions on how to make that happen.
February 19, 2017 at 11:23 pm #1377716
Rue NelModeratorHello There,
Thanks for updating in! Please create your sidebar in Appearance > Sidebar first. And then insert this following code in your child theme’s functions.php file.
// Custom sidebar for a specific category // ============================================================================= function custom_blog_sidebar( $default_sidebar ) { $q_object = get_queried_object(); $sidebars = get_option( 'ups_sidebars' ); foreach ( $sidebars as $id => $sidebar ) { if ( is_single() && has_category('your-category-name') ) { if ( array_key_exists( 'my-custom-sidebar', $sidebar ) && $sidebar['my-custom-sidebar'] == 'on' ) { return $id; } } } return $default_sidebar; } add_filter( 'ups_sidebar', 'custom_blog_sidebar', 100 ); // =============================================================================Please make sure that you have inserted the Category and the custom sidebar in the code above.
Please let us know if this works out for you.
February 22, 2017 at 8:33 pm #1382243
JfantasyBooksParticipantSo I plan to do this for multiple sidebars, and I don’t want to have to go into my functions.php every time and add a foreach every time.
The code below let’s you assign on the category’s page, your desired sidebar. Is it possible we could use that to tweak what you gave me a bit?
I obtained this code from the thread, only it’s function is different than what I desire.
//Categories ============ function post_category_add_meta_field() { // this will add the custom meta field to the add new term page ?> <div class="form-field"> <label for="term_meta[category-sidebar]"><?php _e( 'Item\'s Sidebar', '__x__' ); ?></label> <select name="term_meta[category-sidebar]" id="term_meta[category-sidebar]"><?php echo post_category_sidebar_options(); ?></select> <p class="description"><?php _e( 'Select Sidebar','__x__' ); ?></p> </div> <?php } function post_category_edit_meta_field($term) { // put the term ID into a variable $t_id = $term->term_id; // retrieve the existing value(s) for this meta field. This returns an array $term_meta = get_option( "taxonomy_$t_id" ); ?> <tr class="form-field"> <th scope="row" valign="top"><label for="term_meta[category-sidebar]"><?php _e( 'Item\'s Sidebar', '__x__' ); ?></label></th> <td> <select name="term_meta[category-sidebar]" id="term_meta[category-sidebar]"><?php echo post_category_sidebar_options( $term_meta['category-sidebar'] ); ?></select> <p class="description"><?php _e( 'Select Sidebar','__x__' ); ?></p> </td> </tr> <?php } add_action( 'category_edit_form_fields', 'post_category_edit_meta_field', 10, 2 ); add_action( 'category_add_form_fields', 'post_category_add_meta_field', 10, 2 ); function save_post_category_custom_meta( $term_id ) { if ( isset( $_POST['term_meta'] ) ) { $t_id = $term_id; $term_meta = get_option( "taxonomy_$t_id" ); $cat_keys = array_keys( $_POST['term_meta'] ); foreach ( $cat_keys as $key ) { if ( isset ( $_POST['term_meta'][$key] ) ) { $term_meta[$key] = $_POST['term_meta'][$key]; } } // Save the option array. update_option( "taxonomy_$t_id", $term_meta ); } } add_action( 'edited_category', 'save_post_category_custom_meta', 10, 2 ); add_action( 'create_category', 'save_post_category_custom_meta', 10, 2 ); function post_category_sidebar_options ( $default ) { $sidebars = get_option( 'ups_sidebars' ); $option = '<option value="sidebar-main" '.( !isset($default) || empty($default) || $default == 'sidebar-main' ? ' selected ' : '' ).'>Default</option>'; foreach ( $sidebars as $id => $sidebar ) { $option .= '<option value="'.$id.'" '.( $id==$default ? ' selected ' : '' ).'>'.$sidebar['name'].'</option>'; } return $option; }February 23, 2017 at 12:42 am #1382480
Rue NelModeratorHello There,
Thanks for updating in! Could you please give us the url of that thread? The best thing I could do is forward that thread to the person who gave the code since he is the only one who has a better understanding of how this code should work with a little modification according to your desired output.
Thank you in advance.
March 12, 2017 at 8:26 pm #1404234
JfantasyBooksParticipantI was referring to this link here : https://community.theme.co/forums/topic/create-sidebar-for-post-category/
Hopefully I didn’t misread.
March 13, 2017 at 1:56 am #1404484
RadModeratorHi there,
It’s best if I could check it directly. Maybe there is a problem with setting ID.
Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:
– Link to your site
– WordPress Admin username / password
– FTP credentialsDon’t forget to select Set as private reply. This ensures your information is only visible to our staff.
Thanks!
-
AuthorPosts
- <script> jQuery(function($){ $("#no-reply-1377193 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>
