Note that there are some explanatory texts on larger screens.

plurals
  1. POBootstrap carousel 3.0 in gallery posts WordPress working code refine it?
    primarykey
    data
    text
    <p>I have a working code to show in index.php and content-gallery.php of wordpress with bootstrap carousel 3.0 But I know is not clean code. anybody could help me to clean it? This is the code we need generate to bootstrap carousel works: </p> <pre><code>&lt;div id="carousel-example-generic" class="carousel slide"&gt; &lt;!-- Indicators --&gt; &lt;ol class="carousel-indicators"&gt; &lt;li data-target="#carousel-example-generic" data-slide-to="0" class="active"&gt;&lt;/li&gt; &lt;li data-target="#carousel-example-generic" data-slide-to="1"&gt;&lt;/li&gt; &lt;li data-target="#carousel-example-generic" data-slide-to="2"&gt;&lt;/li&gt; &lt;/ol&gt; &lt;!-- Wrapper for slides --&gt; &lt;div class="carousel-inner"&gt; &lt;div class="item active"&gt; &lt;img src="..." alt="..."&gt; &lt;div class="carousel-caption"&gt; ... &lt;/div&gt; &lt;/div&gt; ... &lt;/div&gt; &lt;!-- Controls --&gt; &lt;a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"&gt; &lt;span class="icon-prev"&gt;&lt;/span&gt; &lt;/a&gt; &lt;a class="right carousel-control" href="#carousel-example-generic" data-slide="next"&gt; &lt;span class="icon-next"&gt;&lt;/span&gt; &lt;/a&gt; &lt;/div&gt; </code></pre> <p>This is the content of my content-gallery-php:</p> <pre><code>&lt;!-- Carousel ================================================== --&gt; &lt;div id="carousel-example-generic" class="carousel slide"&gt; &lt;?php function_indicators($post) ?&gt; &lt;div class="carousel-inner"&gt; &lt;?php function_slides($post) ?&gt; &lt;/div&gt; &lt;!-- Controls --&gt; &lt;a class="left carousel-control" href="#carousel-example-generic" data-slide="prev"&gt; &lt;span class="icon-prev"&gt;&lt;/span&gt; &lt;/a&gt; &lt;a class="right carousel-control" href="#carousel-example-generic" data-slide="next"&gt; &lt;span class="icon-next"&gt;&lt;/span&gt; &lt;/a&gt; &lt;/div&gt; &lt;!-- /.carousel --&gt; </code></pre> <p>And here are 3 functions to my functions.php:</p> <pre><code>function wp_get_attachment( $attachment_id ) { $attachment = get_post( $attachment_id ); return array( 'alt' =&gt; get_post_meta( $attachment-&gt;ID, '_wp_attachment_image_alt', true ), 'caption' =&gt; $attachment-&gt;post_excerpt, 'description' =&gt; $attachment-&gt;post_content, 'href' =&gt; get_permalink( $attachment-&gt;ID ), 'src' =&gt; $attachment-&gt;guid, 'title' =&gt; $attachment-&gt;post_title ); } function functions_indicators() { $special_gallery = get_post_gallery( $post, false ); $ids = explode( ",", $special_gallery['ids'] ); $html = '&lt;ol class="carousel-indicators"&gt;'; foreach( $ids as $id ) { $link = wp_get_attachment_url( $id ); $class = ( $i == 0 ) ? 'active ' : ''; $i++; $b=1; $html .= '&lt;li data-target="#carousel-example-generic" data-slide-to="'.($i - $b).'" '. 'class="'.$class.'"&gt;&lt;/li&gt;'; } $html .= '&lt;/ol&gt;'; echo $html; } function function_slides() { $special_gallery = get_post_gallery( $post, false ); $ids = explode( ",", $special_gallery['ids'] ); $html = '&lt;div class="carousel-inner"&gt;'; foreach( $ids as $id ) { $link = wp_get_attachment_url( $id ); $attachment_meta = wp_get_attachment($id); $class = ( $i == 0 ) ? 'active ' : ''; $i++; $html .= '&lt;div class="item '.$class. '"&gt;&lt;img src="' . $link . '"&gt;' . '&lt;div class="carousel-caption"&gt;&lt;h4&gt;'.$attachment_meta['title'].'&lt;/h4&gt;&lt;p&gt;'.$attachment_meta['description']. '&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;'; } $html .= '&lt;/div&gt;'; echo $html;} </code></pre> <p>anybody could help me to clean/improve it? Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload