I am converting a traditional website to WordPress for an animal rescue charity so members can have a blog and more easily update various pages. All has gone well but I am stuck on one key aspect. Viewers of the original site can click on a page that will then display pictures and names of all dogs of a certain size awaiting adoption. The dogs' names and the location of their photos are stored in a database and the photos in a folder. The images are clickable so that the user can pick a dog and see more about it on another page. The original site all works just fine - see link FAMA then please select Small Dogs (for example).

The page view output looks like this - repeated for each dog of course:

div class="dog_box" >
<a href="http://www.famaspain.com/dogfactstemplate.php?name=Bobby"> <p class="name">Bobby</p>
<p class="dog_img"> <img src="smalldogsphotos/bobby1.jpg" height="180" width="180">
 </p></a></div>

and the code used to pull the data from the database is:

<div id="animalphotos"> 

<?php
$db_host = '*********';
$db_user = '*********';
$db_pwd = '*********';

$database = '***********';
$table = "**********";

if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");

if (!mysql_select_db($database))
die("Can't select database");

// sending query
$results = mysql_query("SELECT * FROM $table WHERE type= 'dog' AND category = 'adopt'  AND  placement='Unplaced' AND size = 'small' ORDER BY name");
if (!$results) {
die("Query to show fields from table failed");
}

while($results_array = mysql_fetch_array($results))
    {
        $id = $results_array["id"];
        $image = $results_array["photo1"];
        $name = $results_array["name"];

        echo "<div class=\"dog_box\" >\r";
        echo "\n";
        echo "<a href=\"http://www.famaspain.com/<strong>dogfactstemplate.php</strong>?name=$name\"> <p class=\"name\">".$name."</p>\t\r";
        echo "\n";
     echo "<p class=\"dog_img\"> ". $image ." </p></a>\t\r";
        echo "\n\t";
        echo "</div>";
    }
    echo "<div class=\"clear\"></div>";
?>
</div>   <!-- End Animal Photos -->

The various classes just specify margins and spacing for a neat two column layout.

OK - so what's the problem? Well, if I cut and paste the very same code into a WP page and run it I get each dog's name and image displayed as per the original site - but they are not clickable and the class names are not used to get the right spacing and margins. (Although WP is opening the correct style sheet for these class statements.)

The page view results also show missing info - the a href and the classes. Here is one example from the page source- repeated for each dog:

Bobby
<img src="smalldogsphotos/bobby1.jpg" height="180" width="180">

The WP version link is: FAMA WP version. Again, please view page and select Small Dogs to see the non-clickable images and poorly aligned display.

Since the php, msql, array etc all run OK and every image is displayed I am at a loss to see what is causing the a href and classes not to be picked up.

Can anyone help please - it's driving me nuts!

Member Avatar for LastMitch

@arjay1

Converting website to Wordpress - now no clickable images using php msql

Have you post this on the Wordpress forum?

The reason why I ask it's because it's their products.

Wordpress has forum for issues/questions related to webpages/templates and their platform.

Thanks for replying. Yes, i did post in the WP forum but, as yet, no reply. I thought this might just be a coding issue, or maybe someone with more knowledge than me might see what the problem is. Sorry if you think i should not have posted here.

Member Avatar for LastMitch

Sorry if you think i should not have posted here.

I never said that you can't post it here.

You can it's just that most of the WordPress thread issues are really hard to answer unless those Daniweb members used Wordpress.

It's much easier for you post at WordPress forum.

But regarding about your code. Maybe this line is causing it not to click:

echo "<a href=\"http://www.famaspain.com/<strong>dogfactstemplate.php</strong>?name=$name\"> <p class=\"name\">".$name."</p>\t\r";

Try to closed the white space:

echo "<p class=\"dog_img\">" .$image. "</p></a>\t\r";

But you have to understand you are using a platform and sometimes even though it's PHP, the WordPress platform reads it differently. So maybe you need to know where to add that PHP on the template so it can function.

Thanks for the helpful comments.

Cereal - the strong tag was my error. I had emboldened the link in a post on another site to ask about syntax and left it in here by mistake. It is not in the original code. The sins of cut and paste I'm afraid.

LastMitch - I tried your suggestion but it made no difference but thanks anyway.

However, i have solved the issue. As OPs have suggested - it was a WP issue not one of php per se. The WP plugin i am using to insert php in a page requires the normal opening and closing tags for php to be changed to [php] and [/php] which i had done.

But I missed another change that is required : to change <p> to [p] and </p> to [/p] etc. Once i did this, the code ran OK. Sorry to have troubled non-WP folks who tried to help. I do admire your patience and friendliness not flaming people like me. More power to your respective elbows.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.