• Resolved rsgale

    (@rsgale)


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

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

    (@rsgale)

    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

Viewing 1 replies (of 1 total)
  • The topic ‘Foreach loop that just won't work’ is closed to new replies.