How to display and limit the custom image on sidebar?
-
Hello,
I want to display my page’s custom field “image1” on my sidebar randomly displaying only 5 number of pages excluding the page which is current. I’m weak in coding however I tried this code but it displays only one image of current page. Please guide me.
<?php $id = get_the_id(); $image_id = get_post_meta($id, 'image1', true); if($image_id !=''){ $attachment = wp_get_attachment_image_src($image_id, 'full', false); // it gives array having first parameter source, second parameter width and third parameter height with image sizes: thumbnail, medium, large and full. if(count($attachment) > 0) { ?> <li class="button"><a href="<?php the_permalink(); ?>"><?php echo get_the_title(); ?></a> <li class="dropdown active"> <a href="<?php the_permalink(); ?>"> <div class="destinations-grid"> <img src="<?php echo $attachment[0]; ?>" class="img-responsive" alt=""/> </div> <div class="destinations-grid-info"> <div class="destinations-hotel"> <p><?php echo get_the_content(); ?>. </p></div> <div class="destinations-price"></div> <div class="clearfix"> </div> </div> </a> </li> <?php } } ?>
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘How to display and limit the custom image on sidebar?’ is closed to new replies.