• Im trying to call a random image with PHP from within a template based on the template in use.

    The code I am usuing is ` <?php
    // let’s generate info appropriate to the page being displayed
    if (is_page_template(‘students.php’)) {
    // we’re on the students page, so let’s show the students quotes

    echo “<img src=\”<?php bloginfo( ‘template_url’ ); ?>/assets/images/quote_students_”;
    echo “<?php echo rand(1,4) ?>”;
    echo “.gif\” />”;
    } else {
    // catch-all for everything else
    echo “<img src=\”<?php bloginfo(‘template_url’); ?>/assets/images/quote<?php echo rand(1,4) ?>.gif\”>”;
    }
    ?>`

    It seems the echo cant handle the <?php calls I have in there..

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

    (@overhaulmedia)

    Nevermind got it!!!

    // let's generate info appropriate to the page being displayed
    if (is_page_template('students.php')) {
            // we're on the students page, so let's show the students quotes
            echo "<img src=\"";
    		bloginfo('template_url');
    		echo "/assets/images/quote_students_";
    		echo rand(1,4);
    		echo ".gif\" />";
    } else {
            // catch-all for everything else
            echo "<img src=\"";
    		bloginfo('template_url');
    		echo "/assets/images/quote_";
    		echo rand(1,4);
    		echo ".gif\" />";
    }
    ?>

Viewing 1 replies (of 1 total)
  • The topic ‘PHP help within templates’ is closed to new replies.