• Resolved ssorcdivad

    (@forefront)


    I want to do a conditional template include based on tags in current post but cannot find anywhere in Codex on how I could do this.

    IF post contains tag 'carrot' OR 'potato' OR 'bean'
       include template 'vegetables'
    ELSE IF post contains tag 'chicken' OR 'beef' OR 'pork'
       include template 'meat'
    ELSE IF post contains tag 'cod' OR 'salmon' OR 'tilapia'
       include template 'fish'
    ELSE
       include template 'default'

    Thank you!

Viewing 1 replies (of 1 total)
  • Thread Starter ssorcdivad

    (@forefront)

    Duh! man answers own post – this works:

    <?php
     if (has_tag(array('carrot','potato','bean'))) {
    	include(TEMPLATEPATH . "/vegetables.php");
     if 	(has_tag(array('chicken','beef','pork'))) {
    	include(TEMPLATEPATH . "/meat.php");
     if 	(has_tag(array('cod','salmon','tilapia'))) {
    	include(TEMPLATEPATH . "/fish.php");
     } else {
    	include(TEMPLATEPATH . "/default.php");
    }
    ?>
Viewing 1 replies (of 1 total)

The topic ‘Include template based on tags in current post’ is closed to new replies.