1

I have a custom post type named 'product', with taxonomies 'brand' and 'type'.

I'd like to have Archive Page A:

  • sidebar with all the 'brand' terms linking to their respective archive page
  • list of all the products that belong to the term.

I'd like to have Archive Page B:

  • sidebar with all the 'type' terms linking to their respective archive page
  • list of all the products that belong to the term.

When I click on a permalink of a product on Archive Page A, it should direct me to Single Page A

  • sidebar with all the 'brand' terms linking to their respective archive page
  • content of the product

And similarly when I click on a product link on Archive Page B, it should direct me to Single Page B

  • sidebar with all the 'type' terms linking to their respective archive page
  • content of the product

How do I achieve this result in WordPress?

1

Archive pages A & B already exist as your brand and type term archives, you can style those differently by creating taxonomy-brand.php and taxonomy-type.php templates.

The remaining piece is two different single product views. The simplest way to achieve that would be to append a GET var onto the permalinks:

http://domain.com/product/someproduct/?origin=brand
http://domain.com/product/someproduct/?origin=type

WordPress has the built in function add_query_arg to help add that for you:

echo add_query_arg( 'origin', 'brand', get_permalink() );

Then in your single post template you can check the value of $_GET['origin'] to determine what to display in the sidebar.

  • Thank you! Actually I managed to solve it this way. Is there a way to remove the GET variable from the URL? Can I at least hide it somehow? Or is there another superglobal I could use that is invisible? – Tamás Jan 7 '15 at 21:35
  • the issue is that you are dealing with separate http requests, so you have to persist the data between the requests. that means either GET, POST, cookie, or session. Cookies and sessions will be per-user, so will be much less performant and break if you want to employ caching. Your other option is to add rewrite endpoints which will make the URLs look a bit nicer, like http://domain.com/product/someproduct/type/ and http://domain.com/product/someproduct/brand/ or http://domain.com/product/someproduct/origin/type/ – Milo Jan 7 '15 at 21:45
  • I've read the documentation but can't figure out how to actually implement that fucntion. Could you please help? – Tamás Jan 8 '15 at 20:21
  • this answer shows an example of adding a rewrite endpoint and loading a different template. – Milo Jan 8 '15 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.