Postingan lainnya
Membuat Slider News Carousel di Codeigniter
Hallo, saya ingin membuat slider seperti dibawah ini, namun saya mengalami kegagalan saat proses integrasinya.
Berikut contohnya Carousel yang ingin saya adaptasikan: <a href='https://bootsnipp.com/snippets/featured/news-carousel '>https://bootsnipp.com/snippets/featured/news-carousel </a>
Ini contoh kode script codeigniter saya:
<?php
$slide1 = $this->model_utama->view_join_two('berita','users','kategori','username','id_kategori',array('headline' => 'Y','status' => 'Y'),'id_artikel','DESC',0,5);
$no=1;
foreach ($slide1->result_array() as $row) {
if ($row['gambar'] ==''){ $foto_slide = 'no-image.jpg'; }else{ $foto_slide = $row['gambar']; }
if (strlen($row['judul']) > 40){ $judul = substr($row['judul'],0,140).''; }else{ $judul = $row['judul']; }
echo " <img src='".base_url()."asset/foto_berita/$foto_slide'/>
<a class='judul-slide' href='".base_url()."berita/detail/$row[judul_seo]'>$judul</a>
</div>
</div>";
$no++;
}
?>
1 Jawaban:
wah, agan cuman melakukan perulangan dibagian tag <img> doang. seharusnya tag <div> gan
nih. di html carouselnya kan kek gini
<pre> <!-- Wrapper for slides --> <div class="carousel-inner">
&lt;div class="item active"&gt;
&lt;img src="http://placehold.it/760x400/cccccc/ffffff"&gt;
&lt;div class="carousel-caption"&gt;
&lt;h4&gt;&lt;a href="#"&gt;Lorem ipsum dolor sit amet consetetur sadipscing&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat. &lt;a class="label label-primary" href="http://sevenx.de/demo/bootstrap-carousel/" target="_blank"&gt;Free Bootstrap Carousel Collection&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;!-- End Item --&gt;
&lt;div class="item"&gt;
&lt;img src="http://placehold.it/760x400/999999/cccccc"&gt;
&lt;div class="carousel-caption"&gt;
&lt;h4&gt;&lt;a href="#"&gt;consetetur sadipscing elitr, sed diam nonumy eirmod&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat. &lt;a class="label label-primary" href="http://sevenx.de/demo/bootstrap-carousel/" target="_blank"&gt;Free Bootstrap Carousel Collection&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;!-- End Item --&gt;
&lt;div class="item"&gt;
&lt;img src="http://placehold.it/760x400/dddddd/333333"&gt;
&lt;div class="carousel-caption"&gt;
&lt;h4&gt;&lt;a href="#"&gt;tempor invidunt ut labore et dolore&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat. &lt;a class="label label-primary" href="http://sevenx.de/demo/bootstrap-carousel/" target="_blank"&gt;Free Bootstrap Carousel Collection&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;!-- End Item --&gt;
&lt;div class="item"&gt;
&lt;img src="http://placehold.it/760x400/999999/cccccc"&gt;
&lt;div class="carousel-caption"&gt;
&lt;h4&gt;&lt;a href="#"&gt;magna aliquyam erat, sed diam voluptua&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat. &lt;a class="label label-primary" href="http://sevenx.de/demo/bootstrap-carousel/" target="_blank"&gt;Free Bootstrap Carousel Collection&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;!-- End Item --&gt;
&lt;div class="item"&gt;
&lt;img src="http://placehold.it/760x400/dddddd/333333"&gt;
&lt;div class="carousel-caption"&gt;
&lt;h4&gt;&lt;a href="#"&gt;tempor invidunt ut labore et dolore magna aliquyam erat&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat. &lt;a class="label label-primary" href="http://sevenx.de/demo/bootstrap-carousel/" target="_blank"&gt;Free Bootstrap Carousel Collection&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;!-- End Item --&gt;
&lt;/div&gt;&lt;!-- End Carousel Inner --&gt;
&lt;ul class="list-group col-sm-4"&gt;
&lt;li data-target="#myCarousel" data-slide-to="0" class="list-group-item active"&gt;&lt;h4&gt;Lorem ipsum dolor sit amet consetetur sadipscing&lt;/h4&gt;&lt;/li&gt;
&lt;li data-target="#myCarousel" data-slide-to="1" class="list-group-item"&gt;&lt;h4&gt;consetetur sadipscing elitr, sed diam nonumy eirmod&lt;/h4&gt;&lt;/li&gt;
&lt;li data-target="#myCarousel" data-slide-to="2" class="list-group-item"&gt;&lt;h4&gt;tempor invidunt ut labore et dolore&lt;/h4&gt;&lt;/li&gt;
&lt;li data-target="#myCarousel" data-slide-to="3" class="list-group-item"&gt;&lt;h4&gt;magna aliquyam erat, sed diam voluptua&lt;/h4&gt;&lt;/li&gt;
&lt;li data-target="#myCarousel" data-slide-to="4" class="list-group-item"&gt;&lt;h4&gt;tempor invidunt ut labore et dolore magna aliquyam erat&lt;/h4&gt;&lt;/li&gt;
&lt;/ul&gt; </pre>
na yang di ulang itu, content dalam <div class="carousel-inner">
which is yang ini
<pre> <div class="item active"> <img src="http://placehold.it/760x400/cccccc/ffffff"> <div class="carousel-caption"> <h4><a href="#">Lorem ipsum dolor sit amet consetetur sadipscing</a></h4> <p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat. <a class="label label-primary" href="http://sevenx.de/demo/bootstrap-carousel/" target="_blank">Free Bootstrap Carousel Collection</a></p> </div> </div><!-- End Item --> </pre>
trus yang ini juga harus dibuatr perulangannya
<pre> <ul class="list-group col-sm-4"> <li data-target="#myCarousel" data-slide-to="0" class="list-group-item active"><h4>Lorem ipsum dolor sit amet consetetur sadipscing</h4></li> <li data-target="#myCarousel" data-slide-to="1" class="list-group-item"><h4>consetetur sadipscing elitr, sed diam nonumy eirmod</h4></li> <li data-target="#myCarousel" data-slide-to="2" class="list-group-item"><h4>tempor invidunt ut labore et dolore</h4></li> <li data-target="#myCarousel" data-slide-to="3" class="list-group-item"><h4>magna aliquyam erat, sed diam voluptua</h4></li> <li data-target="#myCarousel" data-slide-to="4" class="list-group-item"><h4>tempor invidunt ut labore et dolore magna aliquyam erat</h4></li> </ul> </pre>
jadi kyk gini :
<pre> <ul class="list-group col-sm-4"> //foreach disini // ulangi contentn ini // li data-target="#myCarousel" data-slide-to="0" class="list-group-item active"><h4>Lorem ipsum dolor sit amet consetetur sadipscing</h4></li> </ul> </pre>