- This topic is empty.
-
AuthorPosts
-
February 16, 2010 at 5:07 pm #28031copperSmithMember
Hello CMS-Tricksters…
(reposted in PHP help from the CMS help under the same topic title)NOTE: this is my first wordpress theme, I have no PHP experience, other than what I’ve deduced from looking at the code already present in the starkers baseline theme.
I really would like to bring in a short description of a post/page or an image caption directlyfrom somewhere’s.
Look at this mock: http://erm.copper29design.com/assets/im … mepage.JPG
The module in the top right is what I am trying to achieve. I feel confident that I can style this thing appropriately, but just need to see it bringing in data that I can use.
http://erm.copper29design.com/our-work/widows-mission
I am able to plop in some code inside the posts "loop" but have a plugin on the side there that I want to use that same code for… within it’s own loop. I know that it has a loop because I’ve used:
Code:But I can’t find where to stick my image caption querying code to be able to echo the caption similarly to what I am doing in the main post area.
Any help/guidance/code would be appreciated. Thanks,
Here’s the code:
PHP where I need to find the loop to insert the code that will be shown after this long chunk:
Code:‘.”n”;
}function xencarousel_admin_footer()
{
global $path, $ajaxpath, $urlpath;
echo ‘‘.”n”;
}function xencarousel_admin_scripts()
{
global $path, $ajaxpath, $urlpath;
if (is_admin()):
$scripts = array(
array(‘name’ => ‘autocomplete’, ‘path’ => $urlpath.’/js/jquery.autocomplete.min.js’, ‘deps’ => array(‘jquery’), ‘ver’=>’1.0.2’),
);foreach($scripts as $script):
wp_enqueue_script($script[‘name’], $script[‘path’], $script[‘deps’], $script[‘ver’], true);
endforeach;
endif;
}function xencarousel_scripts()
{
global $urlpath;
$scripts = array(
array(‘name’ => ‘jquery-jcarousel-lite’, ‘path’ => $urlpath.’/js/jcarousellite.min.js’, ‘deps’ => array(‘jquery’), ‘ver’ => ‘1.0.1’),
array(‘name’ => ‘jquery-easing’, ‘path’ => $urlpath.’/js/jquery.easing.min.js’, ‘deps’ => array(‘jquery’), ‘ver’ => ‘1.1’),
array(‘name’ => ‘jquery-mousewheel’, ‘path’ => $urlpath.’/js/jquery.mousewheel.min.js’, ‘deps’ => array(‘jquery’), ‘ver’ => ‘1.1’),
array(‘name’ => ‘xencarousel’, ‘path’ => $urlpath.’/js/xencarousel.min.js’, ‘deps’ => array(‘jquery’,’jquery-easing’,’jquery-mousewheel’,’jquery-jcarousel-lite’), ‘ver’ => ‘0.9.1’),
);foreach($scripts as $script):
wp_enqueue_script($script[‘name’], $script[‘path’], $script[‘deps’], $script[‘ver’], true);
endforeach;
}function xencarousel_meta_box()
{
if ( function_exists(‘add_meta_box’) ):
add_meta_box(‘xencarousel’,__(‘xen carousel’,’xencarousel’),’xencarousel_post_box’,’post’,’normal’);
add_meta_box(‘xencarousel’,__(‘xen carousel’,’xencarousel’),’xencarousel_post_box’,’page’,’normal’);
endif;
}function xencarousel_post_box()
{
global $urlpath;
if ( isset($_GET[‘post’]) ):
$post = $_GET[‘post’];
else:
$post = ‘-‘.time();
endif;if ($attachment_id = get_post_meta($post, ‘_xencarousel_image_id’, true)):
$image = _xen_get_attachment_image($attachment_id);
else:
$image = array(“”,’100′,’100′);
endif;$src = $image[0];
$width = $image[1];
$height = $image[2];?>
&type=image&TB_iframe=true&width=640&height=322″>Upload a new imageposts WHERE post_type = ‘attachment’ AND post_mime_type LIKE ‘image/%'”;
$results = $wpdb->get_results($sql,ARRAY_A);
$matches = array_filter($results,’_search_string’);
$images = ”;
if (count($matches) > 0):
foreach ($matches as $match):
$images .= $match[‘post_title’] . ‘ [id: ‘.$match[‘id’].’]|’.$match[‘id’].”n”;
endforeach;
else:
$images = ‘No Results’;
endif;
echo $images;
exit;
}function xencarousel_ajax_image()
{
$attachment_id = $_GET[‘xencarousel_image_id’];
$image = _xen_get_attachment_image($attachment_id);
$src = $image[0];
$width = $image[1];
$height = $image[2];
$img = array(‘img’ => urlencode($src), ‘w’ => $width, ‘h’ => $height);
echo json_encode($img);
exit;
}erm.copper29design.com/wp-content/plugins/xen-carousel/xen-carousel.php
function xencarousel_output()
{
$images = _get_carousel_images();?>
query(‘showposts=5&post_type=any’); //Uses same parameters as query_posts
remove_filter(‘posts_join’, ‘_get_custom_field_posts_join’);
remove_filter(‘posts_groupby’, ‘_get_custom_field_posts_group’);while ($carousel_posts->have_posts()) : $carousel_posts->the_post();
$attachment_id = get_post_meta($carousel_posts->post->ID, ‘_xencarousel_image_id’, true);
$image = _xen_get_attachment_image($attachment_id);
$images[] = array(“src” => $image[0], “width”=> $image[1], “height” => $image[2], “title” => the_title(”,”,false), “link” => get_permalink($carousel_posts->post->ID)
);
endwhile;return $images;
}function _get_custom_field_posts_join($join)
{
global $wpdb, $customFields;
return $join . ” JOIN $wpdb->postmeta postmeta ON (postmeta.post_id = $wpdb->posts.ID and postmeta.meta_key = ‘_xencarousel_image_id’) “;
}function _get_custom_field_posts_group($group)
{
global $wpdb;
$group .= ” $wpdb->posts.ID “;
return $group;
}function _search_string(&$value)
{
if (stripos($value[‘post_name’], $_POST[‘q’]) !== false || stripos($value[‘post_title’], $_POST[‘q’]) !== false):
return true;
else:
return false;
endif;
}
?>PHP I will use WITHIN the loop to query the caption data, so that it can render within the div that is displayed from the code above:
Code:$attachments =& get_children( ‘post_type=attachment&post_mime_type=image&post_parent=’ . get_the_id() );
if (empty($attachments)) {
$imageURI = “/location/to/default/image.jpg”;
$imageTitle = “Default Title Text”;
$imageCaption = “Default Caption Text”;
$imageDescription = “Default Description Text”;
}
else {
foreach($attachments as $attachment => $attachment_array );
$imagearray = wp_get_attachment_image_src($attachment, ‘full’, false);
$imageURI = $imagearray[0];
$imageID = get_post($attachment);
$imageTitle = $imageID->post_title;
$imageCaption = $imageID->post_excerpt;
$imageDescription = $imageID->post_content;I will then use, one of these to pull in the data I need. I’ll likely use Title & Caption, but Caption is most important:
Code:AuthorPostsViewing 1 post (of 1 total)- The forum ‘Back End’ is closed to new topics and replies.