Render text in Module if a certain tag is assigned to a post.

Posted in: Newspaper
Post count: 12

Hello,

I am looking to render some HTML code inside module blocks when a certain tag is assigned to a post.

I’ve gotten this snippet working inside loop-single-2.php by adding:

<?php if ( has_tag( 'promoted-content' ) ) : ?>
			<h3 class="promoted-txt">Promoted Content</h3>
		<?php endif; ?>

However, when I add this same snippet to td_module_2.php right under the <?php echo $this->get_title();?>, I get nothing outputted to the screen, even though the ‘promoted-content’ tag is assigned to that post.

How do I get the has_tag() condition to work on these td_module_X.php files? What is the correct syntax to trigger it to work?

See attached screenshots. The first shows the modules blocks I need to render the conditional HTML, and the second screenshot shows a very simple example of how I want it to look just so you know understand my goal.

Note: I am not asking you to help me with the HTML or CSS. I simply need the correct syntax for the has_tag( ‘promoted-content’ ) snippet that will trigger the HTML to output on the frontend.

Thank you for your help.

Blocks (Visual Composer)

Fronend

Post count: 20688

Hi,

Try it like this, seems to work properly
https://www.screencast.com/t/zGy37CT75liq
https://www.screencast.com/t/cMC0e2F3

<?php if ( has_tag( 'promoted-content', $this->post->ID ) ) : ?> <h3 class="promoted-txt">Promoted Content</h3> <?php endif; ?>

Thanks

Post count: 12

Thanks for your quick response. Your solution does in deed work for /includes/modules/td_module_2.php and td_module_6.php (which is an extension of module_2 I believe) so thank you for that!

What files would I edit for the Slide Block and Big Grid 1, and would I use the same syntax you provided?

Post count: 12

Ok, I figured out the Big Grid 1, but the Slide has me stumped. When I open up the td_module_slide.php, I don’t see anywhere I can place the <?php if ( has_tag( 'promoted-content', $this->post->ID ) ) : ?> <h3 class="promoted-txt">Promoted Content</h3> <?php endif; ?>

Can you please help me with this last module?

Post count: 20688

Hi,

That may not be so easy, the slide is a complex element. You could try to integrate the condition where there are other conditions, then check the results
https://www.screencast.com/t/ztgzk4bJG
You can keep testing but it will probably not be easy.

Thanks

Post count: 12

Hmmm, ya that’s all pig latin to me. I tried messing with adding it in there and was met with defeat. Any insight into how it can be accomplished?

Post count: 20688

Hi,

I really couldn’t say. The slide is a dynamic element, unlike default blocks. If there were an easy solution I would give it to you. Keep trying if you want to achieve this.

Thanks

Post count: 12

Bum deal. 🙁

Viewing 8 posts - 1 through 8 (of 8 total)
The forum ‘Newspaper’ is closed to new topics and replies.