2016-08-30 1 views
0

Ich möchte einen Bild-Slider für meine Wordpress-Website. Also habe ich diesen Code geschrieben und möchte, dass jedes Bild automatisch aus der Tabelle geholt wird und das Bild in die Folien eingeblendet wird. Wenn ich diesen Code in <P> Html Tag. Es zeigt alle Dateien, aber wenn ich dies an die Stelle <img scr=""> stelle, dann scheitert es.wordpress slider mit wpdb

<img src="<?php 

global $wpdb; 
$i = 1; 
$options = ''; 
$states = $wpdb->get_col("SELECT image_path FROM `slider_images`"); 

foreach ($states as $state) { 
    $options .= "<option value='{$i}'>{$state}</option>"; 
    $i++; 

} 
echo $options; 
?>" alt="Chania" width="460" height="345"> 
+0

Warum setzen Sie die ''

Antwort

0

Haben Sie so etwas wie dieses

<?php 
global $wpdb; 
$options = ''; 
$states = $wpdb->get_col("SELECT image_path FROM `slider_images`"); 

$i = 1; 
foreach ($states as $state => $state_value) { 
    echo '<img class="image'.$i.'" src='.$state_value.' alt="Chania" width="460" height="345">'; 
    $i++; 
} 

Da setzen <option> Tags in Ihrem Bild macht absolut keinen Sinn bedeuten ...

Ich weiß nicht, was Ihre Abfrage zurückgeben sollte, so Ich vermute, dass es in Ordnung ist.

+0

Danke! Aber es funktioniert nicht –

0

Dies ist der Bild-Slider, ans ich möchte dies in meiner Wordpress-Website verwenden. Ich habe eine externe Tabelle mit Bildern, also verwende ich $ wpdb. Ich möchte, wenn ich das Bild in der Datenbank speichern, den Schieberegler automatisch holen und neue Bild Folie machen.

<!DOCTYPE html> 
 
<html lang="en"> 
 
<head> 
 
    <title>Bootstrap Example</title> 
 
    <meta charset="utf-8"> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
 
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
 
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 
    <style> 
 
    .carousel-inner > .item > img, 
 
    .carousel-inner > .item > a > img { 
 
     width: 100%; 
 
     margin: auto; 
 
    } 
 
    </style> 
 
</head> 
 
<body> 
 

 
<div class="container"> 
 
    <br> 
 
    <div id="myCarousel" class="carousel slide" data-ride="carousel"> 
 
    <!-- Indicators --> 
 
    <ol class="carousel-indicators"> 
 
     <li data-target="#myCarousel" data-slide-to="0" class="active"></li> 
 
     <li data-target="#myCarousel" data-slide-to="1"></li> 
 
     <li data-target="#myCarousel" data-slide-to="2"></li> 
 

 
    </ol> 
 

 
    <!-- Wrapper for slides --> 
 
    <div class="carousel-inner" role="listbox"> 
 

 
     <div class="item active"> 
 
     <img src="img/img_nature_wide.jpg" alt="Chania" width="460" height="345"> 
 
     <div class="carousel-caption"> 
 
      <h3>Chania</h3> 
 
      <p>The atmosphere in Chania has a touch of Florence and Venice.</p> 
 
     </div> 
 
     </div> 
 

 
     <div class="item"> 
 
     <img src="img/img_fjords_wide.jpg" alt="Chania" width="460" height="345"> 
 
     <div class="carousel-caption"> 
 
      <h3>Chania</h3> 
 
      <p>The atmosphere in Chania has a touch of Florence and Venice.</p> 
 
     </div> 
 
     </div> 
 

 
     <div class="item"> 
 
     <img src="img/img_mountains_wide.jpg" alt="Flower" width="460" height="345"> 
 
     <div class="carousel-caption"> 
 
      <h3>Flowers</h3> 
 
      <p>Beatiful flowers in Kolymbari, Crete.</p> 
 
     </div> 
 
     </div> 
 

 
     <!--<div class="item">--> 
 
     <!--<img src="img_flower2.jpg" alt="Flower" width="460" height="345">--> 
 
     <!--<div class="carousel-caption">--> 
 
      <!--<h3>Flowers</h3>--> 
 
      <!--<p>Beatiful flowers in Kolymbari, Crete.</p>--> 
 
     <!--</div>--> 
 
     <!--</div>--> 
 

 
    </div> 
 

 
    <!-- Left and right controls --> 
 
    <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev"> 
 
     <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> 
 
     <!--<span class="sr-only">Previous</span>--> 
 
    </a> 
 
    <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next"> 
 
     <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> 
 
     <!--<span class="sr-only">Next</span>--> 
 
    </a> 
 
    </div> 
 
</div> 
 

 
</body> 
 
</html>

Verwandte Themen