Custom Flickr sidebar code for cell-phone posts
-
I was looking into using a plugin for this, but then realized WP’s features + PHP’s features allow for more direct “grabbing” of posts that flickr automatically adds if they are sent via a cell-phone.
What I do first is set category 1 to my “moblog”, and category 2 becomes my web-based posted updates. In options, I set the default category to “2”.
What this does is now anything flickr posts automatically is a “category 1” post, but anything I manually post via WP (or even a “blog this! in flickr) is a category 2.
Got it so far?Okay, now we will parse our “category 1” posts in a sidebar, get the images, and do whatever with them.
<?php
//Proportional thumbnail creation
function imageResize($width, $height, $target) {
if ($width > $height) {
$percentage = ($target / $width);
} else {
$percentage = ($target / $height);
}
$width = round($width * $percentage);
$height = round($height * $percentage);
return "width="$width" height="$height"";
}//Get posts belonging to moblog category
query_posts('cat=1');//Create "THE LOOP"
while (have_posts()) : the_post();//Put post content into a string
$flickr = get_the_content($more_link_text, $stripteaser, $more_file);//Extract the img URL to another string "$imgurl[1]"
preg_match("|src="(.*?)" alt|",$flickr,$imgurl);//Get img's size into another string for resizing function
$resizewh = getimagesize($imgurl[1]);
?>Look! An image:
<img src=<?=$imgurl[1]?>><?php endwhile; ?>
Why the imageresize function? Well I prefer my images to be thumbnailed a bit, and have a “tooltip” function that will display the full-size image in a popup-box when you mouseover them. So my html code to make a thumbnail is:
<img src=<?=$imgurl[1]?> <?=imageResize($resizewh[0], $resizewh[1], 50);?>>
That makes the maximum dimension (width or height) no greater than 50.Of course, you can add anything you want to the html section (hyperlink the image to the newspost, for example).
I just felt like sharing this, hope you understand it… I’m new to the whole WP/PHP thing.Here’s an img of it in action:
https://mywebpages.comcast.net/gbatools/flickrbar.jpg
(CSS Xray filter, border, etc. added to thumbnail’s style, javascript tooltip popup on mouseover, mouseover contains the img url<?=$imgurl[1]?>
)
- The topic ‘Custom Flickr sidebar code for cell-phone posts’ is closed to new replies.