View Full Version : Hacking the Grain template for a YAPB'd Wordpress install
bobzilla
12-19-2007, 03:06 PM
Not sure if this should actually be here but your the best I've got :)
Along with a small redesign of my blog I'm looking to move my photoblog over from pixelpost to a YAPB's wordpress install. My main problem however is getting the exif data to display the way I want it to. The code included with the Grain template just grabs the EXIF data and takes each line in turn and throws it up on the site like this (http://test.theapochrypha.co.uk/?p=3). I'd like to be able to pick and choose the entries that I show as most of them are not needed.
My skills with php are almost non existant and was hoping you guys might have a clue where I need to start :)
bobzilla
12-19-2007, 04:08 PM
The original code is something like this
<?php
if(!defined('GRAIN_THEME_VERSION') ) die(basename(__FILE__));
/* display photo EXIF data */
if (function_exists('yapb_get_exif')):
$exif = yapb_get_exif();
?>
<table id="exif">
<caption><?php _e("EXIF information", "grain"); ?></caption>
<tbody>
<?php
apply_filters('grain_exif', $exif);
foreach ($exif as $key => $value): ?>
<tr>
<td class="exif-key"><?php echo $key ?></td>
<td class="exif-value"><?php echo $value ?></td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<?php else: ?>
<p><?php _e("This photo has no EXIF data.", "grain"); ?></p>
<?php endif
?>
I was thinking that I could maybe change the foreach loop so that it contained a switch statement along the lines of this
switch ($key)
{
case model:
<tr>
<td class="exif-key"><?php echo "Model" ?></td>
<td class="exif-value"><?php echo $value ?></td>
</tr>
case exposureTime:
<tr>
<td class="exif-key"><?php echo "Exposure" ?></td>
<td class="exif-value"><?php echo $value ?></td>
</tr>
case fnumber:
<tr>
<td class="exif-key"><?php echo "f Number" ?></td>
<td class="exif-value"><?php echo $value ?></td>
</tr>
case isoEquiv:
<tr>
<td class="exif-key"><?php echo "ISO" ?></td>
<td class="exif-value"><?php echo $value ?></td>
</tr>
.
.
.
I'm not sure if thats how I should be going about it though :S
ses5909
12-19-2007, 08:21 PM
Before I read too much code...is this specific only to YAPB? Do you have options to define all of these parameters in the theme?
bobzilla
12-19-2007, 09:06 PM
I believe so although one of the other photoblog mods might use the same code. Havent been able to find any that do so far though.
bobzilla
12-19-2007, 10:30 PM
This seems to do the job but is there another way other than using switch?
<?php
if(!defined('GRAIN_THEME_VERSION') ) die(basename(__FILE__));
/* display photo EXIF data */
if (function_exists('yapb_get_exif')):
$exif = yapb_get_exif();
?>
<table id="exif">
<caption><?php _e("EXIF information", "grain"); ?></caption>
<tbody>
<?php
apply_filters('grain_exif', $exif);
foreach ($exif as $key => $value): ?>
<tr>
<?php
switch ($key)
{
case model:
echo'<tr>';
echo'<td class="exif-key">Model</td>';
echo'<td class="exif-value">'.$value;
echo'</td>';
echo'</tr>';
break;
case exposureTime:
echo'<tr>';
echo'<td class="exif-key">Exposure</td>';
echo'<td class="exif-value">'.$value;
echo'</td>';
echo'</tr>';
break;
case fnumber:
echo'<tr>';
echo'<td class="exif-key">f Number</td>';
echo'<td class="exif-value">'.$value;
echo'</td>';
echo'</tr>';
break;
case isoEquiv:
echo'<tr>';
echo'<td class="exif-key">ISO</td>';
echo'<td class="exif-value">'.$value;
echo'</td>';
echo'</tr>';
break;
}
?>
</tr>
<?php endforeach ?>
</tbody>
</table>
<?php else: ?>
<p><?php _e("This photo has no EXIF data.", "grain"); ?></p>
<?php endif
?>
ses5909
12-25-2007, 06:22 PM
If you don't use a switch you will have a bunch of if/else blocks. A switch is more cleaner (easier to read) in large blocks of code
vBulletin® v3.7.2, Copyright ©2000-2008, Jelsoft Enterprises Ltd.