Hi guys
i have a problem in buliding query
problem :it shows post image and default image
i want to show post image if not available, default image
i have placed the code and function for thumbnail which i used
code
<div class="newssection">
<div class="heading">
<h3>Latest Posts in <a href="'.$cat_link.'" title="'.$cat_name.'">'.$cat_name.'</a> category</h3>
<div class="clear"></div>
</div>
global $post;
$myposts = get_posts("numberposts=1&category=$cat_number");
foreach($myposts as $post)
{
$posttitle = get_the_title();
$posttime = get_the_time('F jS, Y');
$postauthor = get_the_author();
$postlink = get_permalink();
$text = get_the_excerpt();
$text = substr($text , 0, 150);
$nothumb = get_bloginfo('template_directory');
$thumb = dp_attachment_image($post->ID, "Thumbnail", true);
echo '<div class="article">';
echo '<div class="left">';
echo '<img src="';
if ($thumb == NULL) { echo ''.$nothumb.'/images/defaultthumb.jpg'; } else { echo $thumb; }
echo '" alt="'.$posttitle.'" />';
echo $posttime.'<br />';
echo $postauthor;
echo '</div>';
function for thumb
# Displays post image attachment (sizes: thumbnail, medium, full)
function dp_attachment_image($postid=0, $size='thumbnail', $attributes='') {
if ($postid<1) $postid = get_the_ID();
if ($images = get_children(array(
'post_parent' => $postid,
'post_type' => 'attachment',
'numberposts' => 1,
'post_mime_type' => 'image',)))
foreach($images as $image) {
$attachment=wp_get_attachment_image_src($image->ID, $size);
?><img src="<?php echo $attachment[0]; ?>" <?php echo $attributes; ?> /><?php
}
}