Mengatur Layout Homepage Blogger Dengan Bootstrap

Mengatur Layout Homepage Blogger Dengan Bootstrap

Ismail
Diupdate oleh Ismail
6 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 domunetasinya 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:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
    <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/.