Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #221642

    Paul R
    Moderator

    Hi,

    Thank you for providing login credentials.

    I added back and fix your wp-single.php file.

    Please make sure you have selected a sidebar for your category.

    http://screencast.com/t/3v66oTjOyyI

    Hope that helps.

    #221793

    evanarc
    Participant

    Excellent! Thank you!

    #222095

    Christopher
    Moderator

    You’re welcome.

    #236615

    Chris G
    Participant

    I am attempting to do the same as the original poster of this thread: assign a specific sidebar for each posts category to appear on all single posts of that category. Without any alterations to the functions.php or wp-single.php file, the main sidebar shows up on all single posts pages.

    http://www.creamofthewest.com/15/

    I added the code that you provided in this thread to modify the functions.php and wp-single.php files to display the assigned category sidebar on all single posts pages but I get the following error message on all post pages now:

    Notice: Undefined index: post-category-sidebar in /home/creamoft/public_html/15/wp-content/themes/x-child-integrity-light/framework/views/integrity/wp-single.php on line 36

    Line 36 of the wp-single.php is:
    $sidebar = $setting[‘post-category-sidebar’];

    I have categories and posts throughout the site, not just in the blog. For an example of the error, you can view this page:
    https://creamofthewest.com/15/recipes/cream-west-cowboy-pancakes/

    I’m probably just missing something obvious, but I’ve read this entire thread and I think I’ve done what’s been advised. Am I missing something?

    #236807

    Rad
    Moderator

    Hi Chris,

    What you did is correct, but your debugging is currently enabled. That’s why it’s displaying notices and warning which are not related to errors.

    Please disable your debugging by editing your site’s wp-config.php by setting WP_DEBUG to false.

    Eg. define('WP_DEBUG', false);

    Please also note that you need to edit each of your category to assign sidebars for this to work. Or else, it will still use the main sidebar.

    Cheers!

    #236865

    Chris G
    Participant

    Thanks for your quick reply. I appreciate it. I’ve disabled the debugging. Now nothing shows up. I have assigned a sidebar to each of my categories within Posts > Categories, but they, nor the main sidebar, are showing up. Are you sure that error wasn’t the cause of the problem?

    #236929

    Rad
    Moderator

    Hi Chris,

    Yes, php notice is same as warning, and they aren’t the same as error. But your issue could be from something else. Would you mind starting a new thread pointing here, and provide your admin and ftp login credentials in private? I’ll take a quick check to find what’s the real issue.

    Thanks!

    #237129

    Chris G
    Participant
    This reply has been marked as private.
    #237270

    Rad
    Moderator

    Hi there,

    I can successfully logged with ftp but it disconnect after 20seconds. Directoty listing isn’t even working.

    Please check and let us know.

    Thanks.

    #237483

    Chris G
    Participant

    Not sure what the problem is. The credentials I gave you are correct. I can login via FTP without an issue, both through Dreamweaver and Filezilla. I use regular FTP (not FTPS, SFTP, etc.) and I allow Passive FTP. Depending on the FTP program, you may need to connect to the main root, then navigate to the /15/ directory. Thanks for your efforts!

    #237623

    Rad
    Moderator

    Thanks I’m in 😉

    The issue is that you changed this field name post-category-sidebar to category-sidebar but you didn’t change the one from wp-single.php

    They should match together, and there is no need for editing. You can paste the given code as is 🙂

    Though, I renamed the field name at your wp-single.php to match it.

    Check now https://creamofthewest.com/15/recipes/cream-west-cowboy-pancakes/

    Cheers!

    #237731

    Chris G
    Participant

    This is great! Thank you very much!

    #237734

    Rad
    Moderator

    You’re soo welcome 🙂

    Good luck!

    #244180

    Buttermelts
    Participant

    Hello,

    I’ve added the code from the latter of the two posts to the functions.php file as well as made the replacements to the wp-single.php file. I backed up both files just in case.

    I’m having the same problem where the content is being shifted to the right and a blank space where the custom sidebar is supposed to be. I restored the original wp-single.php file and everything went back to normal, but it’s only the main sidebar being shown in the posts, not the desired custom sidebar.

    I am using the Ethos stack and I’ve set the global settings to content left, sidebar right. I’ve also made sure to check the Archive and Blog layout settings for Use Global Settings and not Fullwidth. In the sidebar options I’ve ticked off the desired category under ‘Taxonomy”. I’ve also enabled the sidebar on the blog index page and child pages. I then went to the category itself > edit > Item’s Sidebar > then set the desired sidebar.

    Is there anything else I can try? Is there an updated version of the wp-single.php edits that I should apply instead of the ones listed already in the earlier post? Unfortunately, I’m working locally right now so I can’t provide any credentials.

    Any help would be appreciated. Thanks.

    #244194

    Buttermelts
    Participant

    If it matter, I’m using X ver. 3.2.3.

    This is what I appended to the functions.php file:

    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;
    }

    And this is my wp-single.php file:

    <?php
    
    // =============================================================================
    // VIEWS/ETHOS/WP-SINGLE.PHP
    // -----------------------------------------------------------------------------
    // Single post output for Ethos.
    // =============================================================================
    
    $fullwidth = get_post_meta( get_the_ID(), '_x_post_layout', true );
    
    ?>
    
    <?php get_header(); ?>
      
      <div class="x-container max width main">
        <div class="offset cf">
          <div class="x-main right" role="main">
    
            <?php while ( have_posts() ) : the_post(); ?>
              <?php x_get_view( 'ethos', 'content', get_post_format() ); ?>
              <?php x_get_view( 'global', '_comments-template' ); ?>
            <?php endwhile; ?>
    
          </div>
    
    	<aside class="x-sidebar left" role="complementary">
    
    	<?php
    
    		$terms = get_the_terms( get_the_ID(), 'category' );
    
    		if ( !isset( $terms ) && count( $terms ) == 0 ) $sidebar = 'sidebar-main';
    		else {
    
        			$term = array_pop( $terms );
        			$setting = get_option( "taxonomy_".$term->term_id );
        			$sidebar = $setting['post-category-sidebar'];
    		}
    
    		dynamic_sidebar( $sidebar );
    
    		?>
    
    	</aside>
    
        </div>
      </div>
    
    <?php get_footer(); ?>