• johnasp

    (@johnasp)


    Hi,

    THE PROBLEM

    I have a collection of 9 page templates, the ONLY difference on each page template is in the line below:

    <?php wp_list_pages(‘title_li=&&child_of=18&depth=3’); ?>

    My page templates basically produce a different ‘site map style’ list of different levels of sites page structure. Therefore the only thing that changes in the above PHP is ‘child_of=18’. Where the child-of number indicates the parent page to build the list from. Examples of what I mean are as follows:

    https://jav.towerscape.co.uk/cameras/eastern/
    https://jav.towerscape.co.uk/cameras/north-east/
    https://jav.towerscape.co.uk/cameras/north-west/
    etc

    THE QUESTION
    My question is, is can I somehow capture the pageID of the current page into a variable, use that variable as an arugment in a series of IF statements in a single template, as opposed to having 9 individual templates. Obviouslly having a lot of different page templates is a problem as I have to make changes throughout every page when I make a change to the master template.

Viewing 1 replies (of 1 total)
  • MichaelH

    (@michaelh)

    This code taken from the wp_list_pages() article should do you:

    <?php
      $children = wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0');
      if ($children) { ?>
      <ul>
      <?php echo $children; ?>
      </ul>
      <?php } ?>

    The above example uses $post->ID for the page value, but this will also return the ID of the current queried page:
    <?php $current_page = get_query_var("p");?>

Viewing 1 replies (of 1 total)
  • The topic ‘Can I use the pageID as an argument in an IF?’ is closed to new replies.