I have 4 page templates with same query.

Is it possible to write conditional statement?

  1. If I go to single post view (single.php) from page template 1 (page-main.php) display something (for example show div),
  2. else if I go to single page view (single.php) from page template 2 (page-second.php) display something,
  3. else etc.
  • 4
    Can you give an example of the use-case you're going for here? It's a bit difficult to follow. What are the four different page templates, and what is unique about what needs to appear in single.php based on each custom page template? – Chip Bennett Feb 11 '14 at 22:09
  • 2
    It appears to me that you need to know what was the visitor coming from before landing on a specific page. You could use $_SERVER['HTTP_REFERER'] for that, but it's not 100% reliable as some browsers do not send the required header (see: stackoverflow.com/questions/165975/determining-referer-in-php ). Or you could, on the link leading to the template, add a query var that you can then use to identify the origin. For example: ?origin=page-second and on the page $_GET['origin'] == 'page-second' ... – pixeline Feb 11 '14 at 23:09
  • @pixeline : could you post that as an "answer" in the answer box below and provide some sample code? – s_ha_dum Feb 12 '14 at 4:08

Your Answer

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

Browse other questions tagged or ask your own question.