CMS Development

Aqibjaved
Member

load common template with different content for different pages in wordpress

SOLVE

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. Site

  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
Jake_Lett
Solution
Guide | Partner
Guide | Partner

load common template with different content for different pages in wordpress

SOLVE

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 %}

 

  

View solution in original post

2 Replies 2
Jake_Lett
Solution
Guide | Partner
Guide | Partner

load common template with different content for different pages in wordpress

SOLVE

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 %}

 

  

dennisedson
HubSpot Product Team
HubSpot Product Team

load common template with different content for different pages in wordpress

SOLVE

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

0 Upvotes