Adding Global Block to END of Portfolio page

Hi there,

I want to add a Global Block to the end of a portfolio page - I’ve got the block set up & have read this thread: https://theme.co/apex/forum/t/changes-to-portfolio-main-page/52965 so have already got a header block in place, but how do I add another to the END of my portfolio page? I guess I need to edit the bit of code that goes into the functions.php file, but to what?

Thanks :slight_smile:

Hi @Gingerfizz_Marketing,

You have to setup a child theme first:

After that add this custom code under functions.php file locates in your child theme:

add_action( "x_after_the_content_end", "add_post_shortcode" );
function add_post_shortcode() {
	if(is_singular( 'x-portfolio' )){
		echo do_shortcode( '[cs_gb id=381]' );
	}
}

Don’t forget to replace the 381 number with your global block ID.

Hope it helps :slight_smile:

Hi Thai,
That doesn’t work - it’s added to individual portfolio posts instead of the main portfolio page (which is where it needs to go) - how do I add it there?
Thanks!

Hey @Gingerfizz_Marketing,

Please update the code to:


add_action( 'x_after_the_content_end', 'add_post_shortcode' );
function add_post_shortcode() {
	if(is_post_type_archive( 'x-portfolio' )){
		echo do_shortcode( '[cs_gb id=381]' );
	}
}

Here’s a link for reference:

https://developer.wordpress.org/reference/functions/is_post_type_archive/

Hope this helps.

Hi @Jade,
That still doesn’t work & I’ve tried several versions. Please advise.
Thank you :slight_smile:

Hello @Gingerfizz_Marketing,

Sorry if the code did not work for you. I want to clarify where you want to display the global block first. Do you want it to insert at the end of the Portfolio page? If that is the case, please make use of this code instead:

add_action( 'x_before_the_content_end', 'add_post_shortcode' );
function add_post_shortcode() {
	if( x_is_portfolio() ){
		echo do_shortcode( '[cs_gb id=381]' );
	}
}

We would love to know if this has worked for you. Thank you.

Hi @RueNel,

I’m afraid it hasn’t worked again. Yes, I want to display it at the end of the portfolio page (which in this case is called Projects - https://xeniapestovabennett.com/projects/)

There are 9 projects displayed on the main portfolio (Projects) page & I want to add a global block beneath them. There is already a global block applied to the top of the page as a header.

Please advise.
Thank you.

Hey @Gingerfizz_Marketing,

Sorry again. I used the incorrect action hook. The correct one should be this:

add_action( 'x_after_view_global__portfolio', 'add_post_shortcode' );
function add_post_shortcode() {
	if( x_is_portfolio() ){
		echo do_shortcode( '[cs_gb id=381]' );
	}
}

If this code still does not work then we will have to edit the template layout itself. To do that, please follow these steps below:
1] Using Notepad or TextEdit or Sublime Text or any text editor, please create a new file in your local machine.
2] Insert the following code into that new file

<?php

// =============================================================================
// VIEWS/INTEGRITY/TEMPLATE-LAYOUT-PORTFOLIO.PHP
// -----------------------------------------------------------------------------
// Portfolio page output for Integrity.
// =============================================================================

get_header();

?>

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

      <?php x_get_view( 'global', '_portfolio' ); ?>

      <?php echo do_shortcode( '[cs_gb id=381]' ); ?>

    </div>

    <?php get_sidebar(); ?>

  </div>

<?php get_footer(); ?>

3] Save the file named as template-layout-portfolio.php
4] Upload this file to your server in the child theme’s folder wp-content/themes/x-child/framework/views/integrity/

You will need to create the folder path since it does not exist in your child theme yet.

Kindly let us know which one work out for you.

Hi @RueNel,
That first one works - thank you…but, I want it to be full width! I’m guessing thats due to the Portfolio page template though, rather than the global block? Is that correct & is there an easy fix that won’t display the portfolio posts across the full page width?

I may be asking too much! :smiley:
Thank you though - it’s appreciated.

Hello @Gingerfizz_Marketing,

If you want the global block to be fullwidth then it has to be inserted outside of the content container. Please make use of this code instead:

add_action( 'x_before_view_integrity_wp_footer', 'add_post_shortcode' );
function add_post_shortcode() {
	if( x_is_portfolio() ){
		echo do_shortcode( '[cs_gb id=381]' );
	}
}

Or maybe this:

add_action( 'x_after_view_footer_base', 'add_post_shortcode' );
function add_post_shortcode() {
	if( x_is_portfolio() ){
		echo do_shortcode( '[cs_gb id=381]' );
	}
}

Or the easiest way is by altering the template using this code:

<?php

// =============================================================================
// VIEWS/INTEGRITY/TEMPLATE-LAYOUT-PORTFOLIO.PHP
// -----------------------------------------------------------------------------
// Portfolio page output for Integrity.
// =============================================================================

get_header();

?>

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

      <?php x_get_view( 'global', '_portfolio' ); ?>

    </div>

    <?php get_sidebar(); ?>

  </div>

<?php echo do_shortcode( '[cs_gb id=381]' ); ?>

<?php get_footer(); ?>

Please let us know which one works best for you.

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