Mengatur Layout Homepage Blogger Dengan Bootstrap

Mengatur Layout Homepage Blogger Dengan Bootstrap

Ismail
Diupdate oleh Ismail
1 - 2 menit

Halo, selamat datang di Identips!, Artikel ini merupakan bagian dari artikel Cara Membuat Tema Blogger Sendiri Menggunakan Bootstrap . Pada artikel ini saya akan membahas cara mengatur layout homepage pada blogger dengan Bootstrap 4.

Pada Artikel sebelumnya saya sudah membahas cara mengatur layout index blogger dengan bootstrap. Sebenarnya juga termasuk index page, akan tetapi disini saya akan menambahkan slider postingan populer dihalaman beranda atau homepage agar terlihat lebih ramai.

Sekarang mari kita mulai membuat post slider di homepage.

Cara membuat post slider dengan Bootstrap

Post slider yang akan saya buat ini menggunakan Bootstrap Carousel With Captions, untuk dokumentasinya silahkan lihat di https://getbootstrap.com/docs/4.5/components/carousel/#with-captions. Dalam halaman dokumentasi Bootstrap, kita ditunjukan kode untuk membuat Carousel atau slider seperti berikut:

    <div id="carouselExampleCaptions" class="carousel slide" data-ride="carousel">
    <ol class="carousel-indicators">
        <li data-target="#carouselExampleCaptions" data-slide-to="0" class="active"></li>
        <li data-target="#carouselExampleCaptions" data-slide-to="1"></li>
        <li data-target="#carouselExampleCaptions" data-slide-to="2"></li>
    </ol>
    <div class="carousel-inner">
        <div class="carousel-item active">
        <img src="..." class="d-block w-100" alt="...">
        <div class="carousel-caption d-none d-md-block">
            <h5>First slide label</h5>
            <p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
        </div>
        </div>
        <div class="carousel-item">
        <img src="..." class="d-block w-100" alt="...">
        <div class="carousel-caption d-none d-md-block">
            <h5>Second slide label</h5>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
        </div>
        </div>
        <div class="carousel-item">
        <img src="..." class="d-block w-100" alt="...">
        <div class="carousel-caption d-none d-md-block">
            <h5>Third slide label</h5>
            <p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>
        </div>
        </div>
    </div>
    <a class="carousel-control-prev" href="#carouselExampleCaptions" role="button" data-slide="prev">
        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
    </a>
    <a class="carousel-control-next" href="#carouselExampleCaptions" role="button" data-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
    </a>
    </div>

Kode diatas akan kita terapkan kode diatas pada widget Postingan Populer, dan hasilnya seperti berikut ini:

    <b:if cond='data:blog.url == data:blog.homepageUrl'>
        <b:section class='slider' id='post-slider' maxwidgets='1' showaddelement='no'>
            <b:widget id='PopularPosts2' locked='true' title='Postingan Populer' type='PopularPosts' version='1'>
                <b:widget-settings>
                    <b:widget-setting name='numItemsToShow'>3</b:widget-setting>
                    <b:widget-setting name='showThumbnails'>true</b:widget-setting>
                    <b:widget-setting name='showSnippets'>true</b:widget-setting>
                    <b:widget-setting name='timeRange'>ALL_TIME</b:widget-setting>
                </b:widget-settings>
                <b:includable id='main'>
                    <div class='carousel slide mb-3' data-ride='carousel' id='carouselExampleInterval'>
                        <ol class='carousel-indicators'>
                            <li class='active' data-slide-to='0' data-target='#carouselExampleCaptions' />
                            <li data-slide-to='1' data-target='#carouselExampleCaptions' />
                            <li data-slide-to='2' data-target='#carouselExampleCaptions' />
                        </ol>
                        <div class='carousel-inner'>
                            <b:loop index='i' values='data:posts' var='post'>
                                <b:with value='data:post.featuredImage' var='image'>
                                    <b:if cond='data:i == 1'>
                                        <a class='carousel-item active' data-interval='5000' expr:href='data:post.href'>
                                            <img class='d-block w-100 p-0 rounded' expr:src='data:image' />
                                            <div class='carousel-caption'>
                                                <h5>
                                                    <data:post.title />
                                                </h5>
                                                <small class='d-none d-md-block'>
                                                    <b:eval expr='snippet(data:post.snippet, {length: 100})' /></small>
                                            </div>
                                        </a>
                                        <b:else />
                                        <a class='carousel-item' data-interval='3000' expr:href='data:post.href'>
                                            <img class='d-block w-100 p-0 rounded' expr:src='data:image' />
                                            <div class='carousel-caption'>
                                                <h5>
                                                    <data:post.title />
                                                </h5>
                                                <small class='d-none d-md-block'>
                                                    <b:eval expr='snippet(data:post.snippet, {length: 100})' /></small>
                                            </div>
                                        </a>
                                    </b:if>
                                </b:with>
                            </b:loop>
                        </div>
                        <a class='carousel-control-prev' data-slide='prev' href='#carouselExampleInterval' role='button'>
                            <span aria-hidden='true' class='carousel-control-prev-icon' />
                            <span class='sr-only'>Previous</span>
                        </a>
                        <a class='carousel-control-next' data-slide='next' href='#carouselExampleInterval' role='button'>
                            <span aria-hidden='true' class='carousel-control-next-icon' />
                            <span class='sr-only'>Next</span>
                        </a>
                    </div>
                </b:includable>
            </b:widget>
        </b:section>
    </b:if>

Sekarang kita simpan kode diatas dibawah tah <article>, jadi hasilnya akan seperti ini:

    <article id='article-wrapper'>
        <b:if cond='data:blog.url == data:blog.homepageUrl'>            <b:section class='slider' id='post-slider' maxwidgets='1' showaddelement='no'>                <b:widget id='PopularPosts2' locked='true' title='Postingan Populer' type='PopularPosts' version='1'>                    <b:widget-settings>                        <b:widget-setting name='numItemsToShow'>3</b:widget-setting>                        <b:widget-setting name='showThumbnails'>true</b:widget-setting>                        <b:widget-setting name='showSnippets'>true</b:widget-setting>                        <b:widget-setting name='timeRange'>ALL_TIME</b:widget-setting>                    </b:widget-settings>                    <b:includable id='main'>                        <div class='carousel slide mb-3' data-ride='carousel' id='carouselExampleInterval'>                            <ol class='carousel-indicators'>                                <li class='active' data-slide-to='0' data-target='#carouselExampleCaptions' />                                <li data-slide-to='1' data-target='#carouselExampleCaptions' />                                <li data-slide-to='2' data-target='#carouselExampleCaptions' />                            </ol>                            <div class='carousel-inner'>                                <b:loop index='i' values='data:posts' var='post'>                                    <b:with value='data:post.featuredImage' var='image'>                                        <b:if cond='data:i == 1'>                                            <a class='carousel-item active' data-interval='5000'                                                expr:href='data:post.href'>                                                <img class='d-block w-100 p-0 rounded' expr:src='data:image' />                                                <div class='carousel-caption'>                                                    <h5>                                                        <data:post.title />                                                    </h5>                                                    <small class='d-none d-md-block'>                                                        <b:eval expr='snippet(data:post.snippet, {length: 100})' />                                                        </small>                                                </div>                                            </a>                                            <b:else />                                            <a class='carousel-item' data-interval='3000' expr:href='data:post.href'>                                                <img class='d-block w-100 p-0 rounded' expr:src='data:image' />                                                <div class='carousel-caption'>                                                    <h5>                                                        <data:post.title />                                                    </h5>                                                    <small class='d-none d-md-block'>                                                        <b:eval expr='snippet(data:post.snippet, {length: 100})' />                                                        </small>                                                </div>                                            </a>                                        </b:if>                                    </b:with>                                </b:loop>                            </div>                            <a class='carousel-control-prev' data-slide='prev' href='#carouselExampleInterval'                                role='button'>                                <span aria-hidden='true' class='carousel-control-prev-icon' />                                <span class='sr-only'>Previous</span>                            </a>                            <a class='carousel-control-next' data-slide='next' href='#carouselExampleInterval'                                role='button'>                                <span aria-hidden='true' class='carousel-control-next-icon' />                                <span class='sr-only'>Next</span>                            </a>                        </div>                    </b:includable>                </b:widget>            </b:section>        </b:if>        <b:section class='main' id='main'>
            <b:widget id='Blog1' locked='true' title='Posting Blog' type='Blog' version='1'>
                <b:widget-settings>
                    <b:widget-setting name='showDateHeader'>false</b:widget-setting>
                    <b:widget-setting name='style.textcolor'>#000000</b:widget-setting>
                    <b:widget-setting name='showShareButtons'>false</b:widget-setting>
                    <b:widget-setting name='showCommentLink'>true</b:widget-setting>
                    <b:widget-setting name='style.urlcolor'>#008000</b:widget-setting>
                    <b:widget-setting name='showAuthor'>false</b:widget-setting>
                    <b:widget-setting name='disableGooglePlusShare'>false</b:widget-setting>
                    <b:widget-setting name='style.linkcolor'>#0000ff</b:widget-setting>
                    <b:widget-setting name='style.unittype'>TextAndImage</b:widget-setting>
                    <b:widget-setting name='style.bgcolor'>#ffffff</b:widget-setting>
                    <b:widget-setting name='showAuthorProfile'>false</b:widget-setting>
                    <b:widget-setting name='style.layout'>1x1</b:widget-setting>
                    <b:widget-setting name='showLabels'>true</b:widget-setting>
                    <b:widget-setting name='showLocation'>false</b:widget-setting>
                    <b:widget-setting name='showTimestamp'>true</b:widget-setting>
                    <b:widget-setting name='postsPerAd'>1</b:widget-setting>
                    <b:widget-setting name='showBacklinks'>false</b:widget-setting>
                    <b:widget-setting name='style.bordercolor'>#ffffff</b:widget-setting>
                    <b:widget-setting name='showInlineAds'>false</b:widget-setting>
                    <b:widget-setting name='showReactions'>false</b:widget-setting>
                </b:widget-settings>
                <b:includable id='main'>
                    <b:if cond='data:blog.pageType == &quot;index&quot;'>
                        <div class='row row-cols-1 row-cols-md-2'>
                            <b:loop values='data:posts' var='post'>
                                <b:include data='post' name='index' />
                            </b:loop>
                        </div>
                        <b:include name='nextprev' />
                    </b:if>
                    <b:loop values='data:posts' var='post'>
                        <b:include data='post' name='post' />
                    </b:loop>
                </b:includable>
                <b:includable id='index' var='post'>
                    <div class='col mb-4'>
                        <div class='card'>
                            <b:if cond='data:post.firstImageUrl'>
                                <img class='card-img-top' expr:alt='data:post.title'
                                    expr:src='data:post.firstImageUrl' />
                            </b:if>
                            <div class='card-body'>
                                <a expr:href='data:post.url'>
                                    <h5 class='card-title'>
                                        <data:post.title />
                                    </h5>
                                </a>
                                <p class='card-text'>
                                    <b:eval expr='snippet(data:post.snippet, {length: 100})' />
                                </p>
                            </div>
                        </div>
                    </div>
                </b:includable>
                <b:includable id='post' var='post'>
                    <b:if cond='data:blog.pageType == "item" or data:blog.pageType == "static_page"'>
                        <div>
                            <!-- Post Start -->
                            <div class='card mb-3' itemprop='blogPost' itemscope='itemscope'
                                itemtype='http://schema.org/BlogPosting'>
                                <b:if cond='data:post.firstImageUrl'>
                                    <meta expr:content='data:post.firstImageUrl' itemprop='image_url' />
                                </b:if>
                                <meta expr:content='data:blog.blogId' itemprop='blogId' />
                                <meta expr:content='data:post.id' itemprop='postId' />
                                <a expr:name='data:post.id' />
                                <b:if cond='data:post.firstImageUrl'>
                                    <img class='card-img-top' expr:src='data:post.firstImageUrl'
                                        expr:alt='data:post.title' />
                                </b:if>
                                <div class='card-body mb-0 pb-0'>
                                    <b:if cond='data:post.title'>
                                        <h2 class='card-title' itemprop='name'>
                                            <data:post.title />
                                        </h2>
                                    </b:if>
                                    <b:if cond='data:top.showTimestamp'>
                                        <span class='card-text'>
                                            <small class='text-muted'>
                                                Oleh
                                                <data:post.author /> &#8226; Di update pada
                                                <data:post.timestamp />
                                            </small>
                                        </span>
                                    </b:if>
                                    <hr />
                                </div>
                                <div class='card-body pt-0 mt-0' expr:id='&quot;post-body-&quot; + data:post.id'
                                    expr:itemprop='(data:blog.metaDescription ? &quot;&quot; : &quot;description &quot;) + &quot;articleBody&quot;'>
                                    <data:post.body />
                                </div>
                                <div class='card-footer'>
                                    <div class='post-footer-line post-footer-line-1'>
                                        <b:if cond='data:post.labels'>
                                            <b:loop values='data:post.labels' var='label'>
                                                <span class='badge badge-success'>
                                                    <a class='text-white' expr:href='data:label.url' rel='tag'>
                                                        #
                                                        <data:label.name />
                                                    </a>
                                                </span>
                                            </b:loop>
                                        </b:if>
                                    </div>
                                </div>
                            </div>
                            <!-- Post End -->
                            <b:include name='nextprev' />
                            <div class="card p-3 mb-3">
                                <b:include data='post' name='comment_picker' />
                            </div>
                        </div>
                    </b:if>
                </b:includable>
                <b:includable id='nextprev'>
                    <div class='d-flex justify-content-between mb-3'>
                        <b:if cond='data:newerPageUrl'>
                            <a expr:href='data:newerPageUrl'
                                expr:id='data:widget.instanceId + &quot;_blog-pager-newer-link&quot;'
                                expr:title='data:newerPageTitle'>
                                <button type="button" class="btn btn-outline-primary">
                                    <data:newerPageTitle /></button>
                            </a>
                        </b:if>
                        <b:if cond='data:olderPageUrl'>
                            <a expr:href='data:olderPageUrl'
                                expr:id='data:widget.instanceId + &quot;_blog-pager-older-link&quot;'
                                expr:title='data:olderPageTitle'>
                                <button type="button" class="btn btn-outline-primary">
                                    <data:olderPageTitle /></button>
                            </a>
                        </b:if>
                    </div>
                </b:includable>
            </b:widget>
        </b:section>
    </article>

tampilannya setelah diterapkan pada Blogger silahkan lihat langsung di https://template-blogger-bootstrap-2.blogspot.com/.