How would I plugin-ify this?
-
I have a function that works great as a page template… but I’d like to be able to use it in posts. The way it is now, if I use the following in a page template it takes the directory and appends the page slug to the end of it, and generates a page of thumbnails that are linked to the pages (in this case though, they use lightbox2) I’d like to be able to call on this in a post say <thumbs> or something and, using the post slug the same way, generate the thumbnail list. I suck at writing PHP from scratch so honestly I don’t know where to begin… but the guts of this is written.
<?php
/*
Template Name: Projects
*/
?>
<div class="post">
<?php$imgurl = '/bench/wordpress/projects/'.$post->post_name; // the directory, where your images are stored
$imgdir = '/home/nolageek/public_html/bench/wettermark/wordpress/projects/'.$post->post_name;
$allowed_types = array('png','jpg','jpeg','gif'); // list of filetypes you want to show
echo $imgdir;$dimg = opendir($imgdir);
while($imgfile = readdir($dimg))
{
if(in_array(strtolower(substr($imgfile,-3)),$allowed_types))
{
$a_img[] = $imgfile;
sort($a_img);
reset ($a_img);
}
}$totimg = count($a_img); // total image number
for($x=0; $x < $totimg; $x++)
{
$size = getimagesize($imgdir.'/'.$a_img[$x]);// do whatever
$halfwidth = ceil($size[0]/3);
$halfheight = ceil($size[1]/3);
echo '<a href="'.$imgurl.'/'.$a_img[$x].'" rel="lightbox"><img style="float:left; padding:5px;border: 1px solid black; margin: 5px;"src="'.$imgurl.'/'.$a_img[$x].'" height="50"</a>';
}
?>
<br clear="both" />
</div>
- The topic ‘How would I plugin-ify this?’ is closed to new replies.