我为我的WordPress项目创建了一个自定义插件。该插件需要正确创建表和插入数据。
如何创建滑块以在WordPress模板上显示图像?
<?PHP
global $wpdb;
$table_name = $wpdb->prefix . "skcelebs";
$img_tbl = $wpdb->prefix . "skimg";
$sql = $wpdb->get_results("SELECT * FROM $table_name ");
foreach ($sql as $r) {
$sql1 = $wpdb->get_results("SELECT * FROM $img_tbl WHERE celeb_id = '" . $r->id . "' ");
?>
<div class="row" style="margin-top:20px">
<div class="col-md-4">
<div class="slider single-item">
<?php
foreach ($sql1 as $si) {
// print_r($si);
//echo $si->name;
?>
<img src="../wp-content/uploads/celebs/<?php echo $si->name; ?>"/>
<?php
}
?>
</div>
</div>
<div class="col-md-8" style="margin-bottom:20px;font-family: Verdana, Geneva, sans-serif ">
<div class="row">
<div class="col-md-8" style="font-size: 2vw ;color: #7E7FB7"><?php echo $r->title; ?></div>
<div class="col-md-8"><?php echo $r->description; ?></div>
<div class="col-md-12">
<a href="<?php echo $r->fb; ?>" target="_blank"><i class="fa fa-2x fa-facebook" aria-hidden="true"></i></a>
<a href="<?php echo $r->tw; ?>" target="_blank"><i class="fa fa-2x fa-twitter" aria-hidden="true"></i></a>
<a href="<?php echo $r->insta; ?>" target="_blank"><i class="fa fa-2x fa-instagram" aria-hidden="true"></i></a>
<a><i class="fa fa-2x fa-youtube-square" aria-hidden="true"></i></a>
<a href="<?php echo $r->yt1; ?>" target="_blank">video1</a>
<a href="<?php echo $r->yt2; ?>" target="_blank">video2</a>
<a href="<?php echo $r->yt3; ?>"target="_blank">video3</a>
</div><br/><br/>
<div class="col-md-5" style="margin-top: 5px"><a href="http://localhost/projects/celebs/?p=56"><button type="button" class="btn btn-info">VIEW AVAILABILITY</button></a></div>
<div class="col-md-2"></div>
<div class="col-md-2"></div>
<div class="col-md-2"></div>
<div class="col-md-2"></div>
</div>
</div>
</div>
<?php } ?>
答案 0 :(得分:0)
请你替换这一行。
<img src="../wp-content/uploads/celebs/<?php echo $si->name; ?>"/>
这一行
<img src="<?php echo get_site_url(); ?>/wp-content/uploads/celebs/<?php echo $si->name; ?>"/>