0

我有一个工作代码显示在 index.php 和 wordpress 的 content-gallery.php 与引导轮播 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的3个函数:

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;}

有人可以帮我清理/改进它吗?提前致谢

4

0 回答 0