AGC Image Dari Flickr,oke langsung saja heheheh,untuk membuat agc image dengan source flickr ada 2 cara.
1.menggunakan API kunjungi http://www.flickr.com/services/api/
2.menggunakan RSS kunjungi http://www.flickr.com/services/feeds/
di sini akan ane tulis contoh cara membuat agc dari flickr dengan menggunakan RSS,kode yang di gunakan sama dengan kode yang ada di sini.
sedikit cuplikan dari http://www.flickr.com/services/feeds/
Feed Formats
All Flickr feeds can be requested in a number of formats using a format parameter. The following values are accepted:
rss_200 or rss2
An RSS 2.0 formatted feed.
atom_1 or atom
An Atom 1.0 formatted feed.
rss_091
An RSS 0.91 formatted feed.
rss_092 or rss
An RSS 0.92 formatted feed.
rss_100 or rdf
An RSS 1.0 formatted feed.
rss_200_enc
An RSS 2.0 formatted feed with enclosures (but without enclosure sizes).
Other feed formats include php, php_serial, csv, json, sql, yaml, cdf and more.
Feed Languages
All Flickr feeds can be requested in a number of languages using a lang parameter. The following values are accepted:
de-de
German
en-us
English
es-us
Spanish
fr-fr
French
it-it
Italian
ko-kr
Korean
pt-br
Portuguese (Brazilian)
zh-hk
Traditional Chinese (Hong Kong)
dari situ kita pilih feed untuk public photo & video,parameter rss2 dan languange biarin default (en-us).hasil ahir url feed yang kita dapatkan kurang lebih seperti ini
http://api.flickr.com/services/feeds/photos_public.gne?format=rss2&tags=keywords&tagmode=any
oke mulai memasang kode php untuk membuat agc dari url feeds tersebut
pertama kita buat fungsi untuk memanggil keywords
untuk halaman search :
1
2
3
4
| <?php
$cari = urlencode($s);
$cari = preg_replace('/([^a-z0-9]+)/i',' ',$cari);
?> |
untuk halaman single / 404 :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| <?php
function agcku_judul(){
$basename = str_replace(array('.php','.html','.htm'),'',basename($_SERVER['REQUEST_URI']));
$ser = array ('@[/]+@', '@(..*)@', '@[-]+@', '@[_]+@', '@[s]+@', '@archives@','@(?.*)@','/d/');
$replace = array (' ', '', ' ', ' ', ' ', '', '','');
$term = preg_replace($ser, $replace, $basename);
$term = trim($term);
return $term;
}
?>
<?php
$cari = agcku_judul();
$cari = preg_replace('/([^a-z0-9]+)/i',' ',$cari);
?> |
kemudian proses penggunaan feed
1
2
3
4
5
6
7
8
| <?php
include_once(ABSPATH . WPINC . '/feed.php');
$rss = fetch_feed('http://api.flickr.com/services/feeds/photos_public.gne?format=rss2&tags='.str_replace(" ",",",$cari).'&tagmode=any');
if (!is_wp_error( $rss ) ) :
$maxitems = $rss->get_item_quantity(6);
$rss_items = $rss->get_items(0, $maxitems);
endif;
?> |
proses menampilkan hasil :
1
2
3
4
5
6
7
| <?php if ($maxitems == 0)
echo ' ';
else
foreach ( $rss_items as $item ) : ?>
<h2><?php echo $item->get_title();?></h2>
<p><?php $item->get_description();?></p>
<?php endforeach; ?> |
untuk mengambil gambar nya saja tanpa title / deskripsi bisa pake kode seperti berikut ini (gambar bawaan feed ukuran thumbnail)
1
2
3
4
5
6
7
8
9
10
| <?php if ($maxitems == 0)
echo ' ';
else
foreach ( $rss_items as $item ) : ?>
<?php
$gambare = $item->get_description();
preg_match('/<img src="(.*?)"/i', $gambare, $gambar);
$gambar = $gambar[1]; ?>
<img src="<?php echo $gambar;?>">
<?php endforeach; ?> |
kalau ingin gambar dalam ukuran aslinya
1
2
3
4
5
6
7
8
9
10
| <?php if ($maxitems == 0)
echo ' ';
else
foreach ( $rss_items as $item ) : ?>
<?php
$gambare = $item->get_description();
preg_match('/<img src="(.*?)"/i', $gambare, $gambar);
$gambar = $gambar[1]; ?>
<img src="<?php echo str_replace("_m","",$gambar);?>">
<?php endforeach; ?> |
selesai