Dynamic content based on a URL parameter

So, I'm doing some wordpress development studies and classes, and now I got an project to work on, and need to get the following task done: I'm doing a telecom website. The site has a page called "Buy" with its custom template. The ideia is that all other pages of services are linking to this page. I want this page to handle all service "order" requests from users.

So it would look like this: www.example.com/buy/

And let's say, the user choose the 50MB Fiber internet plan: www.example.com/buy/?product=fiber50

Conclusion, if "Buy" page comes with "product" URL parameter, the content of the page should change too, because the prices, description and other details are different from each internet plan or other kind of service.

I'm struggling to find a solution for that, but i've researched a lot the past few days and didn't find any solution.

Think would be something like that: https://stackoverflow.com/questions/15099821/wordpress-accept-incoming-url-with-variable-parameters

Thank you by any help!

Topic wp-query php urls content Wordpress

Category Web


My suggestion would be to use a custom page template. In your functions file you require a php file that contains the custom template.

require_once 'buy_page_template.php';

and that file declares itself to be a template by containing some commented out text:

<?php
/* Template Name: Buy Page */

Once you've uploaded and required that file, a new template appears as a possibility in all your pages in Wordpress. You just set the page "buy" to use that template. You can put all the PHP you want into that template, and access the GET variable coming in just like you saw in the other question you cited.

What I do is copy and modify a template file from the theme I'm using.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.