Featured image for Wp Geo Map Mashup

Here is the code to use featured images on maps.  Works with custom content type manager.  You can use wp_query to add more elements to the query.  Specify your post type then add this to functions:

function my_wpgeo_markers( $markers ) {
$custom = new WP_Query();
$custom->query(‘post_type=custom_post_type_name&posts_per_page=-1’);
$i = 1;
while ($custom->have_posts()) : $custom->the_post();
$title = get_the_title();
$content = get_the_content();
$slug = basename(get_permalink());
$slug = str_replace(“-“, “_”, $slug);
$post_id = get_the_ID();
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘thumbnail’ );
$url = $thumb[‘0’];
$thumb_shadow = “add_image_here.png”;

$imageurl = get_post_meta( $post_id, ‘first_gallery_image_meta_box’, TRUE );

$markers[$i] = new WPGeo_Marker(
$slug, // custom post slug
$title, // readable marker text
$content, // info text
30, 30, 10, 34, // width, height, anchorx, anchor y
$url, //image url
$thumb_shadow //image shadow
);

$i++;
endwhile;
return $markers;
}
add_action( ‘wpgeo_markers’, ‘my_wpgeo_markers’ );


If any content is missing the code will break so you might want to include if statements if fields are empty within the function.
ie:
if ($url == “”) {
$url = “default_image_link.png
}


Here is the code for the template page:

NG Gallery custom function – get first image of gallery

I was needing to get the first image of an NGGallery to add it to the meta data in a custom post for the purpose of showing the image for a real estate map with the wp geo plugin. I havent quite figured out how to get the images on the map, although my code is very close.

You may want to get the first image of a gallery to link it to a page or Custom Content Type.  For example, on the real estate website there is a gallery of images, but I may want to show only the first outdoor image as a map thumbnail or as a list of realty properties with the first thumbnail next to each name.  To me it would be a hastle to add the thumbnail as a featured image when there is already a gallery for it and when I know the first gallery image is the outdoor house image.  To get the image I will need the gallery ID that I can get from the post this meta id:

NGGallery dropdown admin menu for posts, pages and custom

The link is another blog post I did that associates a nggallery with the custom content type (ie: realty property).

I can then add this code to my functions:

function nggShowGalleryFirstImage( $galleryID, $template = ”, $images = false ) {

global $nggRewrite;

$ngg_options = nggGallery::get_option(‘ngg_options’);

//Set sort order value, if not used (upgrade issue)
$ngg_options[‘galSort’] = ($ngg_options[‘galSort’]) ? $ngg_options[‘galSort’] : ‘pid’;
$ngg_options[‘galSortDir’] = ($ngg_options[‘galSortDir’] == ‘DESC’) ? ‘DESC’ : ‘ASC’;

// get gallery values
//TODO: Use pagination limits here to reduce memory needs
$picturelist = nggdb::get_gallery($galleryID, $ngg_options[‘galSort’], $ngg_options[‘galSortDir’]);

$first_image = current($picturelist);
$galleryID = intval($first_image->gid);
$first_image_url = $first_image->thumbURL;
echo $first_image_url;

//print_r($first_image);

}

I can get any variable from the first image.  To find the variables just uncomment the print_r and replace the thumbURL with whatever you need from the array.

To use this function, I can place it with the loop of my realty list and get a meta element from the custom post that will read me the gallery id from the above link.

$galleryID = $selected;

nggShowGalleryFirstImage($galleryID);

Custom Content Type Manager – Get list of all elements

Here is the code to get a list of all items in a custom content type.  Put this in your custom template page:

$custom_content_name = new WP_Query();
$custom_content_name->query(‘post_type=custom_content_name&posts_per_page=-1’);

while ($custom_content_name->have_posts()) : $custom_content_name->the_post();
$title = get_the_title();
$content = get_the_content();
$slug = basename(get_permalink());
$post_id = get_the_ID();
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘thumbnail’ );  //gets featured image thumbnail
$url = $thumb[‘0’];

$imageurl = get_post_meta( $post_id, ‘first_gallery_image_meta_box’, TRUE ); //gets image url from the post meta named first_gallery_image_meta_box

echo “<h1>” . $title . “</h1>”;

echo “<p>” . $content . “</p>”;

endwhile;

For more info on Custom Content Type Manager there is documentation here:  http://code.google.com/p/wordpress-custom-content-type-manager/wiki/OutputFilters