• Hello

    I want to include a php file on differnt pages with the same template

    By this I mean:

    I want to include: BEAR.php

    On all pages that use: ANIMALS template

    But is there a way to draw a foldername etc from the pagename?

    SO: A page called DUCK that uses the ANIMALS template calls a file located at DUCK/BEAR.php

    OR:A page called RABBIT that uses ANIMALS template gets file at RABBIT/BEAR.php

    USing:
    <?php include ( TEMPLATEPATH . ‘/BEAR.php’ ); ?>

    Basically I want a file to be called dependant on the pagename without having a seperate template for each page with a spcific php include line.

    Any help much appreciated!

    Dave

Viewing 2 replies - 1 through 2 (of 2 total)
  • Untested but should work:

    <?php
    switch ( the_title( '', '', false) ) {
    	case 'Duck':
    	$filename = 'DUCK';
    	break;
    
    	case 'Bear':
    	$filename = 'BEAR';
    	break;
    
    	[ ...]
    }
    $inc = TEMPLATEPATH . '/' . $filename . '.php';
    include ($inc);
    ?>
    Thread Starter davemcc

    (@davemcc)

    Thanks Esmi

    I shall give this a go, it looks promising!

    Dave

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘php include – draw folder from pagename’ is closed to new replies.