Is there a way to add a hyperlink to each of the images so that when a user clicks a particular image, that the browser will navigate to a different URL? Each image would have a different url associated with it.
<?php
$display = $wpdb->get_results("SELECT name, image_path FROM table_name");
foreach($display as $displays){
?>
<img src ="<?php echo $display->image_path ; ?>"/>
<?php } ?>
So here I want to put a hyperlink for each image retrieved from the database, with the hyperlink navigating to a URL that displays the details about the image. How do I do it?
image tag you cant add link , but you can put the image inside an anchor tag likewise,
If you’ve got the associated link coming from db try this:
Try this ,
Sure, just wrap each
img
tag in your loop in ana
tag, withhref
pointing to the link URL you want.Assuming you can get the url link information the same way you’re getting the image path, it would look something like this: