Show sidebar on child theme and posts with global layout of full-width

Hi,

I tried to check on this: https://theme.co/apex/forum/t/show-sidebar-on-blog-index-and-posts-with-global-layout-of-full-width/6127

We want to change the global layout to full width (without sidebars anymore). but the pages we created in child theme should remain with side bar.

But don’t really get it how to change the child theme pages. Our child theme pages looks like this, could you help?

<?php 
$fullwidth = get_post_meta( get_the_ID(), '_x_post_layout', true );
 get_header(); ?>

  <div class="x-container-fluid max width offset cf">
    <div class="<?php x_main_content_class(); ?>" role="main">

      <?php /*get_template_part( 'template', 'layout-fpmtp_audio' ); */?>
      <?php

// =============================================================================
// From X Theme's VIEWS/GLOBAL/_INDEX.PHP
// -----------------------------------------------------------------------------
// Includes the index output.
// =============================================================================

$stack = x_get_stack();

$paged    = ( ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1 );
  $style     = x_get_option( 'x_archive_style', 'standard' );
  $cols      = 3;

?>

  <?php x_get_view( 'global', '_script', 'isotope-index' ); ?>

  <div id="x-iso-container" class="x-iso-container x-iso-container-posts x-iso-container-fpmtp_audio cols-<?php echo $cols; ?>">

    <?php if ( have_posts() ) : ?>
      <?php while ( have_posts() ) : the_post(); ?>
        <?php x_get_view( $stack, 'content', 'fpmtp_audio' ); ?>
      
      <?php endwhile; ?>
    <?php endif; ?>
  </div>


<?php pagenavi(); ?>

        <?php
// =============================================================================
// End X Theme's VIEWS/GLOBAL/_INDEX.PHP
// =============================================================================

?>
    </div>

    <?php get_sidebar(); ?>

  </div>

<?php get_footer(); ?>

The key to changing the layout is in the code provided on that thread. Here’s a simplified version:

// Make sure that  the blog index has the sidebar
// =============================================================================
function x_child_show_sidebar($contents) {
  if ( true ) {
    $contents = 'sidebar-content';
  }
  return $contents;
}
add_filter('x_option_x_layout_content', 'x_child_show_sidebar', 5);
// =============================================================================

You need to fill in that condition (currently just true) to know when you are using a page with the template you’ve overridden.

This might be as simple as using is_page() as the condition:

// Make sure that  the blog index has the sidebar
// =============================================================================
function x_child_show_sidebar($contents) {
  if ( is_page() ) {
    $contents = 'sidebar-content';
  }
  return $contents;
}
add_filter('x_option_x_layout_content', 'x_child_show_sidebar', 5);
// =============================================================================

However, it really depends on what you are trying to do. If you could let us know the filename of the template you’re overriding that would help. It would also help if you could describe a bit more about how your site works, and what the child theme is doing.

Hi,

Thanks, we have the following template files in the child theme root folder

For instance the archive-fpmtp_audio.php (the code in my first post) corresponds with www.amaravati.org/audio. This is a custom post, shown in this page. When I change the global layout to ‘full width’ the sidebar dissappears then. So I want to ‘force’ this template to use a sidebar on the right (as shown now on www.amaravati.org/audio).

In my functions folder I have registered a sidebar with:

/**
 * Register Sidebar
 */
function fpmtp_register_sidebars() {

	/* Register the sidebar. */
	register_sidebar(
		array(
			'id' => 'sidebar-fpmtp-audio',
			'name' => __( 'Dhamma Talks'),
			'description' => __( 'Dhamma Talks sidebar.' ),
			'before_widget' => '<aside id="%1$s" class="widget %2$s">',
			'after_widget' => '</aside>',
			'before_title' => '<h4 class="widget-title mtn">',
			'after_title' => '</h4>'
		)
	);

If you can show me how to ‘force’ the sidebar, regardless what the global layout setting is, I think I can work out with the the other templates.

Thanks a lot

If you have an Audio custom post type, try updating the code above where it would check if the post type is the audio custom type and audio archive.

Please refer to the following link:

https://codex.wordpress.org/Conditional_Tags#A_Post_Type_Archive

Hope this helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.