Angry Creative

Bloggen

Här skriver vi om saker som angår oss och branschen vi verkar i. Vad vi irriterar oss på, vad som inspirerar oss och vad som förbryllar oss.

Att använda Simple Fields

Pär Thernström har gjort Simple Fields – ett vansinnigt bra plugin till WordPress som förlängar funktionaliteten i WordPress avsevärt. Med hjälp av detta pluginet och det nya Custom post type systemet som introducerades i WP3 så kan man äntligen använda WP som ett ganska komplett CMS.

I detta blogginlägg tänkte jag visa hur man kan använda Simple Fields. För att inte bara svenskar skall förstå kommer jag att kommentera nedanstående på Engelska.

English:

So, this is my little code example getting images with the Simple Fields plugin. This could easily be adapted to be used together with some nice javascript slideshow, enabling slideshows on a per-post basis – very useful, especially together with custom post types.


$selected_value = simple_fields_get_post_group_values(get_the_id(), "Hook-name", false, 2); // make a multidimensional array with values. Hook-name is the name of the hook created with Simple-Fields

for ($k = 0; $k < count($selected_value); $k++) {  // The number of arrays can vary, but we know what kind of fields we use. In this example we have two sets of images with one description.
$image1=$selected_value[$k][1]; // k is the array number, 1 is the position of the field (given to us by simple fields)
$description1=$selected_value[$k][2];

$image2=$selected_value[$k][3];
$description2=$selected_value[$k][4];

if ($image1 != "0") { echo wp_get_attachment_image( $image1, $size='medium',$icon = false ); } else { printf("<img src='fallbackimage.jpg' alt='$description1' title='$description1' />"); } // if there is a picture selected, show that image. If there is no image, use the fallback image.
printf("<div class='description'>$description1</div>"); // print description
if ($image2 != "0") { echo wp_get_attachment_image( $image2, $size='medium',$icon = false ); } else { printf("<img src='fallbackimage.jpg' alt='$description2' title='$description2' />"); }
printf("<div class='description'>$description1</div>");
} // loop ends here.

// enable for debugging

// print("<pre>");
// print_r($selected_value);
// print("</pre>");

Etiketter: ,

Postat i: WordPress