我有一个工作代码显示在indexpress的index.php和content-gallery.php中,带有bootstrap carousel 3.0 但我知道代码不干净。有人可以帮我清理吗? 这是我们需要为引导轮播工作生成的代码:
<div id="carousel-example-generic" class="carousel slide">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="..." alt="...">
<div class="carousel-caption">
...
</div>
</div>
...
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
<span class="icon-prev"></span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
<span class="icon-next"></span>
</a>
</div>
这是我的content-gallery-php的内容:
<!-- Carousel
================================================== -->
<div id="carousel-example-generic" class="carousel slide">
<?php function_indicators($post) ?>
<div class="carousel-inner">
<?php function_slides($post) ?>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
<span class="icon-prev"></span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
<span class="icon-next"></span>
</a>
</div>
<!-- /.carousel -->
以下是我的functions.php的三个函数:
function wp_get_attachment( $attachment_id ) {
$attachment = get_post( $attachment_id );
return array(
'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
'caption' => $attachment->post_excerpt,
'description' => $attachment->post_content,
'href' => get_permalink( $attachment->ID ),
'src' => $attachment->guid,
'title' => $attachment->post_title
);
}
function functions_indicators() {
$special_gallery = get_post_gallery( $post, false );
$ids = explode( ",", $special_gallery['ids'] );
$html = '<ol class="carousel-indicators">';
foreach( $ids as $id ) {
$link = wp_get_attachment_url( $id );
$class = ( $i == 0 ) ? 'active ' : '';
$i++;
$b=1;
$html .= '<li data-target="#carousel-example-generic" data-slide-to="'.($i - $b).'" '. 'class="'.$class.'"></li>';
}
$html .= '</ol>';
echo $html;
}
function function_slides() {
$special_gallery = get_post_gallery( $post, false );
$ids = explode( ",", $special_gallery['ids'] );
$html = '<div class="carousel-inner">';
foreach( $ids as $id ) {
$link = wp_get_attachment_url( $id );
$attachment_meta = wp_get_attachment($id);
$class = ( $i == 0 ) ? 'active ' : '';
$i++;
$html .= '<div class="item '.$class. '"><img src="' . $link . '">' . '<div class="carousel-caption"><h4>'.$attachment_meta['title'].'</h4><p>'.$attachment_meta['description']. '</p></div></div>';
}
$html .= '</div>';
echo $html;}
任何人都可以帮我清理/改善它吗? 提前致谢