Sidebars confusion and Search issues

Hello again my favorite Theme Team :slight_smile:

This time only 4 simple (one can hope) questions from me:

  1. SIDEBARS
    a) I’d like to have Sidebar on my Blog, Archives (both tag and category) Single Articles, but I want a fullwidth layout without Sidebar on my Single Pages. How can I do that?
    b) I’d like to have two different sidebars, one for Single Articles and one for all Archives, Search and Blog. How can I do that? Current “Sidebars” backend doesn’t allow me to set it like this. I can only set whether Sidebar is used on Blog (no setting for archives and search) or select single articles or single taxonomies one by one which is a no-go, since article base and tag base will grow exponentially once site launches.

  2. SEARCH
    a) How can I modify Search Results page title to also feature a phrase that user is searching for? So for example page title for someone who is searching for “science” will be “Search Results for Science” or something along those lines.
    b) How can I change default “Nothing to Show Right Now” title and description? I’d like to write my custom title and text here in my own language (Polish).

DISCLAIMERS:

  • I have child theme setup properly,
  • I work on localhost.

Hi there,

Thanks for posting in.

1.a. Please add this code to your child theme’s functions.php

  function x_get_content_layout() {

    $content_layout = x_get_option( 'x_layout_content' );

    if ( $content_layout != 'full-width' ) {
      if ( is_home() ) {
        $opt    = x_get_option( 'x_blog_layout' );
        $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
      } elseif ( is_singular( 'post' ) ) {
        $meta   = get_post_meta( get_the_ID(), '_x_post_layout', true );
        $layout = ( $meta == 'on' ) ? 'full-width' : $content_layout;
      } elseif ( x_is_portfolio_item() ) {
        $layout = 'full-width';
      } elseif ( x_is_portfolio() ) {
        $meta   = get_post_meta( get_the_ID(), '_x_portfolio_layout', true );
        $layout = ( $meta == 'sidebar' ) ? $content_layout : $meta;
      } elseif ( is_page_template( 'template-layout-content-sidebar.php' ) ) {
        $layout = 'content-sidebar';
      } elseif ( is_page_template( 'template-layout-sidebar-content.php' ) ) {
        $layout = 'sidebar-content';
      } elseif ( is_page_template( 'template-layout-full-width.php' ) ) {
        $layout = 'full-width';
      } elseif ( is_archive() ) {
        if ( x_is_shop() || x_is_product_category() || x_is_product_tag() ) {
          $opt    = x_get_option( 'x_woocommerce_shop_layout_content' );
          $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
        } else {
          $opt    = x_get_option( 'x_archive_layout' );
          $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
        }
      } elseif ( x_is_product() ) {
        $layout = 'full-width';
      } elseif ( x_is_bbpress() ) {
        $opt    = x_get_option( 'x_bbpress_layout_content' );
        $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
      } elseif ( x_is_buddypress() ) {
        $opt    = x_get_option( 'x_buddypress_layout_content' );
        $layout = ( $opt == 'sidebar' ) ? $content_layout : $opt;
      } elseif ( is_404() ) {
        $layout = 'full-width';
      } else {
        $layout = $content_layout;
      }
    } else {
      $layout = $content_layout;
    }

if ( is_singular( 'post' ) || is_home() || is_archive() ) {
$layout = "content-sidebar";
}

if ( is_page() ) {
$layout = "full-width";
}

    return $layout;

  }

1.b. That’s not currently possible with the existing layout. It’s only limited to 2 columns (1 content and 1 sidebar). Though, still doable with custom development and that means you’ll have to create your own CSS, templates, and responsive styling for 3 column template. You may contact a developer for this implementation.

2.a. It’s part of your landmark template, you can go to this folder \x\framework\legacy\cranium\headers\views\{YOUR CURRENT STACK}\ (eg. \x\framework\legacy\cranium\headers\views\integrity\ ) then copy the file _landmark-header.phpto your child theme (like\x-child\framework\legacy\cranium\headers\views\integrity_landmark-header.php`) then change these lines to your own preferred wording.

  <header class="x-header-landmark x-container max width">
    <h1 class="h-landmark"><span><?php _e( 'Search Results', '__x__' ); ?></span></h1>
    <p class="p-landmark-sub"><span><?php _e( "Below you'll see everything we could locate for your search of ", '__x__' ); echo '<strong>&ldquo;'; the_search_query(); echo '&rdquo;</strong>'; ?></span></p>
  </header>

2.b. The same as above, it’s part of the landmark template. It’s under the line <?php elseif ( is_404() ) : ?>.

Though, if all of these is because of translation and not changing the wording, then you should check this https://theme.co/apex/forum/t/setup-translation/61

Thanks!

Thanks for Your answer Rad, great help as allways. Let me break it into parts, so I can understand everything perfectly:

1.a.
Your code works like a charm - does exactly what I wanted it to. I had some trouble understanding it though. From what I got, the part that actually changes layout between “fullscreen” and “sidebar” is the last part:

if ( is_singular( 'post' ) || is_home() || is_archive() ) {
$layout = "content-sidebar";
}

if ( is_page() ) {
$layout = "full-width";
}

I even managed to add my own rule for bbpress so it has “fullwidth” layout too, just to check if I was right:

if ( is_bbpress() ) {
		$layout = "full-width";
}

What I hove trouble understanding though is what the first part of code does. You seem to just check current layout for all possible page sections and just set it as it was (home, buddypress) and at the same time set it without checking in other cases (product, 404). Could You be so nice as to explain why exactly? I feel like big part of this code is reduntant (subjective, low-educated guess and feeling). For the record, I’'m not trying to pick on things, I’m trying to understand this code and learn. Thank You.

1.b.
You didn’t understand me here. I don’t want two sidebars at a time. But I want to assign sidebars to certain “sections” of the site with rules more precise than those available in backend. To clarify:

  • I want sidebar X to be used on all Archives, Search and Blog.
  • I want sidebar Y to be used on all Single Posts.
  • I want sidebar Z to be used on forums (this one is just made up, just to show my point).
    Current backend only allows me to assign sidebars on per-post or per-tag basis which is a no-go since both posts and tags base will grow exponentially with time.

2.a.
I am using Ethos and there is no searched term shown there at all, only “Search Results”. Thanks for pointing me to the one in Integrity. I feel stupid now for not checking other stacks in the first place.

2.b.
It’s more complicated here. I don’t want to change just title but entire content. As of now it looks like this for search results:

Nothing to Show Right Now

It appears whatever you were looking for is no longer here or perhaps wasn’t here to begin with. You might want to try starting over from the homepage to see if you can find what you’re after from there.

…and looks like this for 404:

Oops!

The page you are looking for is no longer here, or never existed in the first place (bummer). You can try searching for what you are looking for using the form below. If that still doesn’t provide the results you are looking for, you can always start over from the home page.

Landmark file only contains “Oops!” title for the 404, not the content. And it doesn’t contain anything at all regarding failed search results page. I want to edit all of the above, both landmark titles, content titles and content itself.

Hi there,

1.a The first part is the default code that comes with the theme. I left it there since there should be always a fall back setting for other pages that don’t require changes such as this sidebar.

Plus, we need to add the custom code outside this block if ( $content_layout != 'full-width' ) { or else, your custom code will not override the layout since it’s checking the condition of full-width. Hence, a separate and outside custom code will perfectly work overriding the previous layout pulled from your theme’s setting.

You can delete the original code, but keep in mind that we’ll not provide support to that extent especially if that affect the functionality of other features. We don’t really provide support for custom codes :slight_smile:

1.b You can go to Admin > Appearance > Sidebars and create your sidebars and assign them. Or like this ( but first, take note the sidebar ID ), add this code to your child theme’s functions.php

add_filter( 'ups_sidebar', 'ups_display_sidebar_custom', 99 );

function ups_display_sidebar_custom( $sidebar) {

if ( is_archive() || is_search() || is_home() )  $sidebar = 'sidebar-id-here-X';
if ( is_singular('post') )  $sidebar = 'sidebar-id-here-Y';
if ( add_the_condition_for_forum_here() )  $sidebar = 'sidebar-id-here-Y';

return $sidebar;
}

2.b. Ah, the content should be available here \framework\views\global\_content-404.php. Same procedure, just different path and file name.

Hope these helps :slight_smile:

1.a. It’s fine as it is, I just wanted to understand the code a little bit more. The more I learn the less I will need to ask later :slight_smile:

1.b. Thanks, this is exactly what I needed. This functions.php filter does what backend options cannot.

2.b. Also great thanks. Exactly the file I needed. And the other file (_content-none.php) was in the same spot so I was able to edit it too.

One last question about translating. In Your tutorials You have information how to change site language, including translating 404 page etc. What about multilingual site (Polylang) though? How can I have 404’s for all my languages (currently only 2 - English and Polish)?

Hi there,

You’ll have to translate them for each site, but if you’ll be using translation files (eg. po and mo files), then you can simply add them to /wp-content/languages/ and it should available for all sites within multi-site. Though, according to Wordpress https://codex.wordpress.org/Multilingual_WordPress. It should be doable with WPML or Polylang.

Same translation procedures apply.

Thanks!