I notice a growing trend towards using pictures to link to posts. Pinterest effect perhaps? Anyway, some people code the pictures listing manually in a HTML/Javascript gadget to form a gallery, while others painstakingly add one picture at a time using a Picture gadget. It's a pain.
But there is a good news: you can now list the pictures easily andautomatically using our recent posts image gallery widget. Perfect for listing recipes, design projects and other photo-centric posts.
Below are some the features of the gallery:
- You can set your preferred image size, any size. Image will come out sharp, no pixelation.
- Light -what you see is what actually loaded. Most image galleries take forever to load because they load full size images and then shrink them using CSS. This gallery loads the correct image size the first time.
- Posts can be filtered using a label.
- Support multiple galleries. The options (thumb size and post title overlay) can be set independently for each gallery.
Installation
- First go to Template > Edit HTML and add this script before the
</head>
tag in your template.01
<
script
>
02
// Blogger Recent Posts Gallery by Bloggersentral.com
03
// Tutorial at http://www.bloggersentral.com/2013/05/recent-posts-image-gallery-for-blogger.html
04
// Free to use or share, but please keep this notice intact.
05
//
<![CDATA[
06
function bsrpGallery(root) {
07
var entries = root.feed.entry || [];
08
var html = ['<div class="bsrp-gallery nopin" title="Get this from BloggerSentral.com">'];
09
for (var i = 0; i < entries.length; ++i) {
10
var post = entries[i];
11
var postTitle = post.title.$t;
12
var orgImgUrl = post.media$thumbnail ? post.media$thumbnail.url : 'https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0she64hies49AFkpIBGsWt7I2zyu4cMfZOv9JyePzBasCyglwm-YB_FO0WjIObV1UMRb-XPa4EawcNCBum43-M2Z2rUlAtGyNXbiogQ2PcFLJd9WA6ZfmSfpkxeLvvEl1pKMWUzw0mXlA/s72-c/default+image.png';
13
var newImgUrl = orgImgUrl.replace('s72-c', 's' + bsrpg_thumbSize + '-c');
14
var links = post.link || [];
15
for (var j = 0; j < links.length; ++j) {
16
if (links[j].rel == 'alternate') break;
17
}
18
var postUrl = links[j].href;
19
var imgTag = '<img src="' + newImgUrl + '" width="' + bsrpg_thumbSize + '" height="' + bsrpg_thumbSize + '"/>';
20
var pTitle = bsrpg_showTitle ? '<span class="ptitle">' + postTitle + '</span>' : '';
21
var item = '<a href="' + postUrl + '" target="_blank" title="' + postTitle + '">' + imgTag + pTitle + '</a>';
22
html.push('<div class="bs-item">', item, '</div>');
23
}
24
html.push('</div>');
25
document.write(html.join(""));
26
}
27
//]]>
28
</
script
>
- Then, add the following CSS code into the CSS section of your template (right before
</b:skin>
tag).1
/* BloggerSentral Recent Posts Image Gallery CSS Start */
2
.bsrp-gallery {
padding
:
10px
;
clear
:
both
;}
3
.bsrp-gallery:after {
content
:
""
;
display
: table;
clear
:
both
;}
4
.bsrp-gallery .bs-item a {
position
:
relative
;
float
:
left
;
margin
:
0
15px
15px
0
!important
;
text-decoration
:
none
;}
5
.bsrp-gallery .bs-item .ptitle {
background
: rgba(
0
,
0
,
0
,
0.5
);
background
:
#7f7f7f
\
9
;
display
:
block
;
clear
:
left
;
font-size
:
11px
;
line-height
:
1.3em
;
height
:
2.6em
;
position
:
absolute
;
text-align
:
left
;
bottom
:
10%
;
color
:
#fff
;
padding
:
2px
5px
; word-wrap: break-word;
overflow
:
hidden
;}
6
.bsrp-gallery a img {
background
:
#eee
;
float
:
left
;
padding
:
5px
; box-shadow:
1px
1px
3px
rgba(
0
,
0
,
0
,
0.5
); -moz-box-shadow:
1px
1px
3px
rgba(
0
,
0
,
0
,
0.5
); -webkit-box-shadow:
1px
1px
3px
rgba(
0
,
0
,
0
,
0.5
); transition: background-color
0.4
s; -webkit-transition: background-color
0.4
s; -moz-transition: background-color
0.4
s;}
7
.bsrp-gallery a:hover img {
background
:
#ee7e22
;}
8
/* BloggerSentral Recent Posts Image Gallery CSS End */
If you prefer to put the CSS together with the scripts (in a post or in a HTML/Javascript gadget), you must enclose it in a</script>
tag. - Finally add this script wherever you want the gallery to appear. It can be added anywhere -in a post, a page or a HTML/Javascript widget.
1
<
script
>
2
var bsrpg_thumbSize = 150;
3
var bsrpg_showTitle = true;
4
</
script
>
5
<
script
src
=
"/feeds/posts/summary?max-results=8&alt=json-in-script&callback=bsrpGallery"
></
script
>
- Set the image size (in pixel) in line 2.
- Set line 3 to
true
to add post title overlay on each image. False will display image without overlay. However, in both cases, the post title will appear in the tooltip that pops up when you hover the image. - To display recent posts under a label (e.g.
RECIPE
), replace the base URL for the src attribute with the label feed URL, like so:/feeds/posts/summary/-/RECIPE
- Set the number of posts to be displayed by changing the value of
max-results
query parameter.
0 comments:
Post a Comment