load common template with different content for different pages in wordpress

SOLVE
Aqibjaved
Member

i have created a template called thank-you.php and inside that i want to show different content as per the parent url.
for e.g. mywebsite.com /page/thank-you and mywebsite.com/another-page/thank-you. here, i need to load same template but with different content as per the parent url.
let's say if i submit the form on mywebsite.com/page, i need to show video related to /page on mywebsite.com/page/thank-you and the same procedure for mywebsite.com/another-page/thank-you which shows video related to /another-page.
Note: I need to show this as end result of hubspot form submission on different pages.

  1. do i need to create a page in admin area for that? unionwells vietnam
  2. do i need to set this page as a child? if so, how can i set as a child for specific pages(around 25 pages)?
  3. how can i solve this problem?

I am new to wordpress. any help is appreciated.

0 Upvotes
1 Accepted solution

Accepted Solutions
BootstrapC
Solution
Top Contributor

UPDATE - I just realized this quesiton is for WordPress and not HubSpot CMS. The logic is the same and just has to be written in PHP. https://stackoverflow.com/questions/7118823/check-if-url-has-certain-string-with-php

 

 

I haven't tested this out but I think should do what you want. Edit your thank-you.php with this code and update the strings you want to match with your unique page names. This will allow you to have one template with content swapped by the url.

 

{% if page_meta.canonical_url is string_containing "/page1/" %}
	<h1>Page 1 content</h1>
{% elif page_meta.canonical_url is string_containing "/page2/" %}
	<h1>Page 2 content</h1>
{% else %}
	<h1>Default content</h1>
{% endif %}

 

  


HubSpot Themes

Jake LettDigital strategy consultant
Creator of the Industrial Pro HubSpot Theme which helps manufacturers quickly build their website or blog on HubSpot.


View solution in original post

2 Replies 2
dennisedson
Community Manager

@webdew , @BootstrapC , either of you able to assist here?

Thanks,

Dennis




Check out our Community Developer Blog
where we feature our Community driven developer podcast and how to content
0 Upvotes
BootstrapC
Solution
Top Contributor

UPDATE - I just realized this quesiton is for WordPress and not HubSpot CMS. The logic is the same and just has to be written in PHP. https://stackoverflow.com/questions/7118823/check-if-url-has-certain-string-with-php

 

 

I haven't tested this out but I think should do what you want. Edit your thank-you.php with this code and update the strings you want to match with your unique page names. This will allow you to have one template with content swapped by the url.

 

{% if page_meta.canonical_url is string_containing "/page1/" %}
	<h1>Page 1 content</h1>
{% elif page_meta.canonical_url is string_containing "/page2/" %}
	<h1>Page 2 content</h1>
{% else %}
	<h1>Default content</h1>
{% endif %}

 

  


HubSpot Themes

Jake LettDigital strategy consultant
Creator of the Industrial Pro HubSpot Theme which helps manufacturers quickly build their website or blog on HubSpot.


View solution in original post