Pro Layouts - Dynamic Data In Shortcode

Hi again,

I have yet another Pro Layouts question!I am building Archive and Single page Layouts for bbPress. Generally it ahs been going well, but I am having a problem with the Topic Single Layout.

The bbPress shortcode for this type of layout is:

[bbp-single-topic id=$topic_id]

where $topic_id is replace by the post ID.

If I use the actual post ID (e.g. 592) and save the Layout, it will render on the front-end.

However, I have been trying to use dynamic data to populate the post ID. This is what I am trying to use:

[bbp-single-topic id={{dc:post:id}}]

It does not render anything on the front-end of the website. I also notice that the Headline in the admin view is also incorrect, despite showing correcly on the front-end.

Is it possible to use dynamic data as I am attempting to? Alternatively, is there a different way to achieve what i am trying to do?

I apologise for so many support queries over the past few days. I hope the responses end up helping others as well as me!

Many thanks,
Christopher

Hi @cdnwhite,

Thanks for reaching out.

I just check your layout in Pro > Layouts > Forum Topic Single and it seems that the bbpress is not able to read the {{dc:post:id}} inside the shortcode. For some workaround, what I did is create a custom shortcode where it gets the post ID then insert the ID inside the shortcode using some PHP code. I added the code below in your functions.php child theme.

function bbpress_get_id() {
     $id = get_the_ID(); ?>
	[bbp-single-topic id=<?php echo $id;?>]
<?php }

add_shortcode('custom_bbpress_id', 'bbpress_get_id');

Then I change your code in your layout from [bbp-single-topic id={{dc:post:id}}] to [custom_bbpress_id] and it is now showing properly on the front-end.

Hope that helps.

Thank you.

Hi @marc_a,

Thank you so much! That is fantastic and is working absolutely perfect, just as I was trying to do.

Really grateful!
Christopher

Hi Christopher,

You’re welcome and it’s our pleasure to help you. If you have any other concerns regarding our theme features, feel free to reach us.

Thank you.

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