WordPress.org

Ready to get started?Download WordPress

Forums

PHP help within templates (2 posts)

  1. overhaulmedia
    Member
    Posted 4 years ago #

    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..

  2. overhaulmedia
    Member
    Posted 4 years ago #

    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\" />";
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.