Images in foreach loop in category array
-
hello everyone,
I think im on the verge of figuring this out after spending alot of time reading php tutorials, but I think i might be missing a few key things as im a beginner!
With the code below, I have $display_categories set as an array with 5 categories. The single_cat_title() function prints the link to the category on the front page, which is sweet and that works pefectly and stuff, but I want a specific image to be shown right below each specific category (so img 1 goes below category 23, image 2 for 24, and so on).
I tried setting the img url’s as variables to be put into array $catimg, but when I try to call the images with <img src=””> under the foreach loop, they do not come up.
Hopefully as im a beginner I’m just missing something obvious, but if an expert could provide their opinion and show me my error, it would be greatly appreciated!
Thank you!!!
<?php // this is where you enter the IDs of which categories you want to display $display_categories = array(23,24,21,19,20); // defines image locations for array $bikebutton = 'img url 1'; $climbbutton = 'img url 2'; $hikebutton = 'img url 3'; $snowbutton = 'img url 4'; $waterbutton = 'img url 5'; //defines image array $catimg = array ($bikebutton, $climbbutton, $hikebutton, $snowbutton, $waterbutton); foreach ($display_categories as $category) { ?> <div class="clearfloat"> <?php query_posts("showposts=1&cat=$category"); $wp_query->is_category = true; $wp_query->is_archive = false; $wp_query->is_home = true; ?> <h3><a href="<?php echo get_category_link($category);?>"><?php // this is where the name of each category gets printed single_cat_title(); ?></a></h3> <img src="<?php echo $catimg?>"> </div> <?php } ?>
- The topic ‘Images in foreach loop in category array’ is closed to new replies.