Adding section or widget below the blog posts on the blog index page

I wanted to see the best way to Add section or widget below the blog posts on the blog index page only at all the posts.

I saw this https://theme.co/apex/forum/t/best-way-to-add-content-block-to-all-blog-posts/56870 and you helped troubleshoot this https://theme.co/apex/forum/t/any-way-to-move-a-be-at-the-top-of-the-blog-post-page-vs-as-a-side-bar/54387 I wanted to keep my bar at the top but I wanted to add a section at the bottom that is either just section block or a widget place. smilar to this https://www.dropbox.com/s/50x88ziyes8rzfi/Screenshot%202019-05-01%2000.40.10.png?dl=0
thanks

Hi @designbabe,

The best way is to create your content using global blocks then add it to your blogpost using hooks.

So add this code in your child theme’s functions.php

function themeco_add_content_below_blog_posts() {
	if ( is_singular('post') ) {
  		echo do_shortcode( '[your-shortcode]' );
	}
}
add_action('x_before_the_content_end', 'themeco_add_content_below_blog_posts');

Change [your-shortcode] with your global block shortcode

Hope this helps

Thanks Paul
will this add to all posts? i was just trying to add to blog index?

Hi @designbabe,

Yes, it will be added to all posts. But I’m a bit confused as you said you wanted to add it below the blog posts but on blog index only. I assume you’re referring to each blog posts in the blog index? If yes then it’s not currently possible. That code will only add it below the page not withing each post items.

Thanks!

HI Rad,
sorry for the confusion. I just want it on the main /blog/ page not on all the individual single post pages. Just the Page that shows all the post excerpts. Just here below the numbers.

Hi @designbabe,

Thank you for the clarification, in that case, you need to update the condition on the code given by Paul from:

if ( is_singular('post') )

to

if ( is_home() )

Wordpress Conditional Tags

Cheers,

HI Friech,
I made a global block and add that to the code supplied with the adjustment for the blog home vs all posts, and somehow my block isn’t showing on the page. what am i missing?

add_action( ‘x_after_view_global__slider-below’, ‘add_mytext’, 10 );
function themeco_add_content_below_blog_posts() {
if ( is_home() )
echo do_shortcode( ‘[cs_gb id=674]’ );
}
add_action(‘x_before_the_content_end’, ‘themeco_add_content_below_blog_posts’);

thanks

Hi @designbabe,

Please try with this code instead:

add_action( 'x_after_view_global__index', 'themeco_add_content_below_blog_posts', 10 );
function themeco_add_content_below_blog_posts() {
     if ( is_home() )
          echo do_shortcode( '[cs_gb id=674]' );
}

Hope it helps :slight_smile:

HI Thai,
thanks so much for assistance.
that worked mostly, but had wanted the section to go end to end even though the blog posts are in the page container. IS there a way to do that just at the bottom?
let me know
thanks so much

Hi @designbabe,

The x_before_view_footer_base is the hook above the footer, I think it would work.

So please change the code to this:

add_action( 'x_before_view_footer_base', 'themeco_add_content_below_blog_posts', 10 );
function themeco_add_content_below_blog_posts() {
     if ( is_home() )
          echo do_shortcode( '[cs_gb id=674]' );
}

Hope it helps :slight_smile:

Hi Thai, yes of course, I should have thought about that… lack of sleep.
thanks so much that worked great
have a great day

You’re welcome, and glad to hear it’s sorted @designbabe.

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