- This topic has 8 replies, 2 voices, and was last updated 5 years, 11 months ago by
Tom.
-
AuthorPosts
-
October 21, 2019 at 11:07 am #1040581
Heather
Hi there,
I would like to add a custom CTA in the 2nd row of all my blog archive pages. I currently have my layout as a 3 column grid showing 9 posts, so I would like the pages to essentially be:
post post post
post post cta
post post postpagination
I know I can add something custom to the archive.php pages, but I am not sure where it would go in the code as it seens like the pages are set up to just do_action (GP theme specific hook/section). Where/how would I add this in the following code:
<div id="primary" <?php generate_do_element_classes( 'content' ); ?>> <main id="main" <?php generate_do_element_classes( 'main' ); ?>> <?php /** * generate_before_main_content hook. * * @since 0.1 */ do_action( 'generate_before_main_content' ); if ( have_posts() ) : /** * generate_archive_title hook. * * @since 0.1 * * @hooked generate_archive_title - 10 */ do_action( 'generate_archive_title' ); while ( have_posts() ) : the_post(); /* * Include the Post-Format-specific template for the content. * If you want to override this in a child theme, then include a file * called content-___.php (where ___ is the Post Format name) and that will be used instead. */ get_template_part( 'content', get_post_format() ); endwhile; /** * generate_after_loop hook. * * @since 2.3 */ do_action( 'generate_after_loop' ); generate_content_nav( 'nav-below' ); else : get_template_part( 'no-results', 'archive' ); endif;
Also, I can not provide a url/login info as this is all being done for a company on my local.
October 21, 2019 at 4:53 pm #1040790Tom
Lead DeveloperLead DeveloperHi there,
As of right now it’s possible without creating a custom template file.
What you want to do is insert your code after the
get_template_part( 'content', get_post_format() );
line.The code you enter should look something like this: https://crunchify.com/how-to-insert-ads-on-home-page-after-2nd-and-5th-post-in-genesis-framework/
I’m working on adding a hook in that area, but want to make sure we do it right (possibly hooking the
get_template_part
into the same hook.October 23, 2019 at 10:37 am #1042683Heather
Does GP use Genesis? Not sure how I would make this code work specifically for GP. I’ve tried to add code after that part, but it messes with the columns layout of the page, so it turns my 3 columns into 2, with a cta randomly on the right side where the 3rd column exists.
Can I create an additional get_template_part or something underneath using that loop counter?
October 23, 2019 at 7:38 pm #1042930Tom
Lead DeveloperLead DeveloperIt doesn’t – I linked to that article because of the specific code they’ve used to insert the ad, which you can place in your custom template:
global $loop_counter; $loop_counter++; if( (!is_paged() && !is_singular()) && ($loop_counter == 1 || $loop_counter == 4)) { echo '<div style="margin-bottom:25px;"><ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-4032710958875645" data-ad-slot="7425196307"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div>'; $loop_counter = $loop_counter + 1; } global $loop_counter_paged; $loop_counter_paged++; if( (is_paged() ) && ($loop_counter == 2 || $loop_counter == 5) ) { echo '<div style="margin-bottom:25px;"><ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-4032710958875645" data-ad-slot="7425196307"></ins><script>(adsbygoogle = window.adsbygoogle || []).push({});</script></div>'; $loop_counter_paged = $loop_counter_paged + 1; }
We don’t have a hook right now, so a custom template is needed, but I’m looking into adding one in the near future.
October 25, 2019 at 7:50 am #1044385Heather
Ok, so I should add this code right below the get_template_part( ‘content’, get_post_format() );
Could you target get_template_part with a custom hook? Like creating an after_get_template_part by selecting custom hook when making a new one?
October 25, 2019 at 9:22 am #1044455Heather
So I added that code under where you said and it worked! Which is great.
However, it seems to be showing up on category archive pages, but not the blog archive (“posts page”) itself.
I added the code to archive.php, is there another php file specific to the blog archive page that shows all posts? I want to add this there as well.
October 25, 2019 at 4:31 pm #1044676Tom
Lead DeveloperLead DeveloperThey don’t have a hook there, unfortunately.
You need to add it to the
index.php
file as well 🙂Hope this helps!
October 28, 2019 at 9:42 am #1046972Heather
That worked, thanks so much!
October 28, 2019 at 4:06 pm #1047296Tom
Lead DeveloperLead DeveloperYou’re welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.