Adding content above Layout - Content Left, Sidebar Right

Hey!

Thanks for the solution, can you clarify what I do with the 2323 page ID?

Hi Andy,

The 2323 number is an example of page ID. You should replace it with your page ID:

If you would like to print the global block shortcode in multiple pages, please the code to this:

<?php if ( is_page( array(1234, 5678, 9870) ) ) do_shortcode('[cs_gb id=381]'); ?>

Hope it helps :slight_smile:

@Rad

So when I change my “Your Homepage Displays” to a static page, it no longer shows my latest posts. How do I find the page ID of my homepage that isn’t a page I actually created?

Hey Andy,

When the page is used as your blog index, is_page() will no longer work. You will used other conditional tag instead like is_home() for the blog index, is_archive() for archive pages. You can check out the codex here for the rest of the available conditions that you can use:

We would loved to know if this has work for you. Thank you.

@Rad @thai

Hi.

There are only 4 php files in my /x/framework/legacy/cranium/headers/views/ethos/ folder. I can’t find the template.

https://puu.sh/CSZiD/03056f4f2a.gif

On top of that, there’s like no folders in my x-child folder.

https://puu.sh/CSZoS/dd3ba5bb6c.gif

Hi Andy,

  1. Do you mean the page templates?

It’s located in wp-content/themes/x/framework/views/ethos

  1. Yes, the child theme by default don’t have those folders. You will need to create the folders and copy over the files that you want to override. Kindly review the link below.

Thanks

@Rad @RueNel

Hi.

Okay here’s what I did:

  1. Found the template-layout-content-sidebar.php in wp-content/themes/x/framework/views/ethos
  2. Copied the file into my wp-content/themes/x-child/framework/views/ethos
  3. Went into my WordPress Theme editor of my child theme and went to the template php file
  4. Added the <?php if ( is_home() ) do_shortcode(’[cs_gb id=2040]’); so it’s like:

https://puu.sh/CSZQ9/b8d36f4628.png

I know you see ( is_home() && is_front_page() )

But I’ve already tried:

  1. ( is_home() )
  2. ( is_home() & is_front_page() )
  3. ( is_home() && is_front_page() )
  4. ( is_front_page() )
  5. ( is_front_page() && is_home() ) {
    // Default homepage
    } elseif ( is_front_page() ) {
    // static homepage
    } elseif ( is_home() ) {
    // blog page
    } else {
    //everything else
    }

I’ve cleared my cache every time, my homepage never updated with my global block.

https://puu.sh/CSZNm/642ef01a4f.gif

Hello Andy,

You need this line:

<?php if ( is_home() )  : ?>
  <?php echo do_shortcode('[cs_gb id=2040]'); ?>
<?php endif; ?>

We would loved to know if this has work for you. Thank you.

@Rad @RueNel

It didn’t change anything either.

https://puu.sh/CT00y/1a89769d35.png

Cleared the cache as well.

Hi,

In that case, would you mind providing us with login credentials so we can take a closer look? Please provide following information:

Set it as Secure Note

  • Link to your site
  • WordPress Admin username / password

All the best!

Of course, here it is:

Hey Andy,

The template you have modified is for pages only. You will need to assign this to your blog index page or any page that uses the Layout - Content Left, Sidebar Right page template.

To resolve your issue, you can simply add this PHP code block in your child theme’s functions.php file instead. No template modifications needed.

// Displaying custom Content on Blog Page
// =============================================================================
function add_custom_content () {

  if( is_home() ) {

    echo do_shortcode('[cs_gb id=2040]');
  
  <?php }

}
add_action('x_after_view_ethos_post-slider', 'add_custom_content');
// =============================================================================

We would loved to know if this has work for you. Thank you.

Hi!

Thanks for the information. I’m only looking to place this global block on my blog homepage anyways.

I’m getting this error when placing that code in my functions.php

Your PHP code changes were rolled back due to an error on line 90 of file wp-content/themes/x-child/functions.php. Please fix and try saving again.

syntax error, unexpected ‘<’

Line 90 is the <?php }

Hello Andy,

There was a typographic error in the code in my reply. Have it updated into this one:

// Displaying custom Content on Blog Page
// =============================================================================
function add_custom_content () {

  if( is_home() ) {

    echo do_shortcode('[cs_gb id=2040]');
  
  }

}
add_action('x_after_view_ethos_post-slider', 'add_custom_content');
// =============================================================================

Please let us know if this works out for you.

Hi.

It still didn’t do anything.

https://puu.sh/CT2tF/6522da154d.png

Hello Andy,

I went ahead and edited your functions.php file.
I used this code instead:

// Displaying custom Content on Blog Page
// =============================================================================
function add_custom_content () {

  if( is_home() ) {

    echo do_shortcode('[cs_gb id=2040]');
  
  }

}
add_action('x_after_view_ethos__landmark-header', 'add_custom_content');

The section were place outside the container just right below the navbar.

Please check it now.

Omg!

It works!

It’s absolutely beautiful :slight_smile:

Thank you all for your help. This was such a struggle for me haha!

You’re most welcome!
We’re glad we were able to help you out.

@Rad @paul.r

The last question I have is if I want to add the same global block on top of a specific category/archive page, what is the code I have to add in the functions.php?

Hi Andy,

It’s going to be similar, example, let’s take this part

  if( is_home() ) {

    echo do_shortcode('[cs_gb id=2040]');
  
  }

You can enhance it to something like this,

  if( is_home() ) {

    echo do_shortcode('[cs_gb id=2040]');
  
  }

  if( is_category( 3232 ) || is_category( 'news' ) ) {

    echo do_shortcode('[cs_gb id=2041]');
  
  }

  if( is_archive() || is_tag() ) {

    echo do_shortcode('[cs_gb id=2043]');
  
  }

  if( is_tax('product_cat', 'music') || is_tax('product_cat', 'audio') ) {

    echo do_shortcode('[cs_gb id=2045]');
  
  }

There is no limitation, as long as you use the conditions provided by Wordpress.

Thanks!