Forums

[resolved] Foreach loop that just won't work (2 posts)

  1. rsgale
    Member
    Posted 7 months ago #

    Hi

    I'm trying to use a really simple foreach loop to build a menu but it just won't work! Please tell me when I'm being so dumb!

    <?php
    	$coverpages = array ('About', 'News', 'Jobs', 'Register');
    
    	foreach ($coverpages as $p) {
    		if ( !is_page('$p') ) { echo "<a href='/$p/'>" };
    		echo "<img src="images/$p.png" alt="" class="buttons ";
    
    		if ( !is_page($p) ) { echo ' hov' };
    		echo '/>" />';
    		if ( !is_page($p) ) { echo '</a>' };?>
    	}
    ?>

    Thanks!!

  2. rsgale
    Member
    Posted 7 months ago #

    Please ignore this - I finally got there!

    For those who are interested, the working code is

    <?php
    	$coverpages = array ('About', 'News', 'Jobs', 'Register');
    
    	foreach ($coverpages as $p) {
    		if ( !is_page($p) ) { echo "<a href='/$p/'>"; };
    		echo "<img src='";
    		bloginfo('template_directory');
    		echo "/images/" . $p . ".png' class='buttons ";
    
    		if ( !is_page($p) ) { echo ' hov'; };
    		echo "'/>";
    		if ( !is_page($p) ) { echo '</a>'; };
    	}
    ?>

    Best, R

Reply

You must log in to post.

About this Topic