Support » Plugins and Hacks » Hacks » Using ONE WP Page as a template to display product detais based on the URL.

  • I have a site doing comparisons of products.
    I have created a WP page that will output the details for a specific product (pulled from a database).
    Rather than creating 1 page per product (very time consuming and not practical), I want to use this one WP page as a kind of template.

    So for example, the custom page “slug” is called: product-details
    if you visit:
    http://www.myblog.com/product/yellow-widget – this would be routed (using httaccess and some custom WP code) to the WP page “product-details” passing the URL text “yellow-widget” as the product identifier and then I’d look up the DB and fetch the product details where product_name = “widget”. And I am not meaning doing a redirect (301, 302 etc). I do not want the URL bar to change (as in redirect to another page)

    Similarly, if you visit:
    http://www.myblog.com/product/blue-widget – this would also be routed (not redirected) to the WP page “product-details” passing the URL text “blue-widget” as the product identifier (eg: $_GET variable – product_id=blue-widget)

    http://www.myblog.com/product/red-widget would do the same, and so on.

    Any suggestions on how best achieve this?

    I know how I can do the PHP code in the page – I have already done this part. But I am not sure the best way I can achieve the URL “masking” (for lack of a better word) – as per my examples above.

    Thanks.

  • The topic ‘Using ONE WP Page as a template to display product detais based on the URL.’ is closed to new replies.