I need to add the "active" or "current-menu-item" class to a custom childpages menu. I've tried the code below but it doesn't seem to work.
I've browsed google but can't find anything that will work!
<?php
$childpages = query_posts('orderby=menu_order&order=asc&post_type=page&post_parent=35&posts_per_page=300');
if ($childpages)
{
// Display the children content
foreach ($childpages as $post)
{
setup_postdata($post)
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="mezzanine-sub-title <?php echo!empty($_GET['page_id']) && $_GET['page_id'] == $post->ID ? "active" : NULL ?>">
<span><?php the_title(); ?></span>
<a>
<?php
global $post;
$src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(5600, 1000), false, '');
?>
<div class="mezzanine-sub-image" style="background: url(<?php echo $src[0]; ?> );border:<?php the_field('border'); ?>;">
</div>
</a>
</a>
<?php
}
}
?>
Thanks in advance
change query_posts to get_posts also you have invalid syntax with your <a> tag.
finally instead of using $get which is not returning anything use wp_query
so your code should be:
$childpages = get_posts('orderby=menu_order&order=asc&post_type=page&post_parent=35&posts_per_page=300');
if ($childpages)
{
// Display the children content
foreach ($childpages as $post)
{
setup_postdata($post)
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="mezzanine-sub-title<?php if ( $post->ID == $wp_query->post->ID ) { echo ' active'; }?>">
<span><?php the_title(); ?></span>
<?php
$src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(5600, 1000), false, '');
?>
<div class="mezzanine-sub-image" style="background: url(<?php echo $src[0]; ?> );border:<?php the_field('border'); ?>;">
</div>
</a>
<?php
}
}
Related
I have displayed wc product's variations as a single product.
Here is link: https://hueslabsstage.wpengine.com/store/
also, you need credentials:
login: hueslabsstage
password: 11test11
I have an issue with ajax load more function. I am using WooCommerce Load More Products by BeRocket. For example, when I choose 2 products to show on load more it really shows 2 products, but with all variations. For example, I have 4 products, the first one and the second one with 2 variations, so the plugin shows me 4 items on the shop page(2 products with 2 variations).
So, I need to display each variation as a single product in the way the plugin sees products. In order to when I choose 2 products to show, the plugin should display 2 variations of the product, instead of 2 products with them all variations.
Hope I explained my issue correctly.
My content-product.php:
<?php
if ($product->is_type('variable')): ?>
<?php
$unique_variations = [];
foreach($product->get_available_variations() as $key => $item) {
if (!variation_exists($item['attributes']['attribute_pa_color'], 'attribute_pa_color', $unique_variations)) {
$unique_variations[] = $item;
}
}
?>
<?php foreach($unique_variations as $variation):
$itemVariation = $variation['variation_id'];
?>
<?php
$meta = get_post_meta($variation['variation_id'], 'attribute_pa_color', true);
if (empty($meta)) {
continue;
}
$term = get_term_by('slug', $meta, 'pa_color');
$color = get_field('product_color', $term->taxonomy . '_' . $term->term_id);
$gallery = get_field('gallery', $variation['variation_id']);
$front_image = wp_get_attachment_image_src($variation['image_id'], 'product-thumbnail')[0];
$back_image = null;
if (!empty($gallery)) {
$back_image = $gallery[0]['sizes']['product-thumbnail'];
}
?>
<article class="<?php echo $outOfStock; ?>">
<?php if ($product_status_badge): ?>
<div class="product_badge">
<img src="<?php echo $product_status_badge; ?>" alt="Product status">
</div>
<?php endif; ?>
<div class="product_images">
<?php
if ( ! $product->managing_stock() && ! $product->is_in_stock() ){
?>
<div class="out_of_stock_overlay">Sold Out</div>
<?php
}
?>
<div class="product_image_items">
<figure>
<a href="<?php echo get_the_permalink() ?>?attribute_pa_color=<?php echo $meta ?>" title="<?php echo get_the_title(); ?>">
<img src="<?php echo $item['image']['url'];?>" alt="<?php echo get_the_title(); ?>" class="front_img">
<img src="<?php echo $back_image;?>" alt="<?php echo get_the_title(); ?>" data-test="<?php echo $back_image;?>" class="back_img">
</a>
<div class="product_arrows">
<div class="arrow_left">
<em class="fal fa-chevron-left"></em>
</div>
<div class="arrow_right">
<em class="fal fa-chevron-right"></em>
</div>
</div>
</figure>
</div>
</div>
<div class="product_top">
<div class="product_left">
<h3 class="product_title"><?php echo get_the_title(); ?></h3>
<div class="price">
<?php if ($product->is_type('variable')): ?>
<?php echo $product->get_variation_price() . " " . get_woocommerce_currency_symbol(); ?>
<?php else: ?>
<?php echo $product->get_price_html(); ?>
<?php endif; ?>
</div>
</div>
<?php if ($product->is_type('variable')): ?>
<?php
$unique_variations = [];
foreach($product->get_available_variations() as $key => $item) {
if (!variation_exists($item['attributes']['attribute_pa_color'], 'attribute_pa_color', $unique_variations)) {
$unique_variations[] = $item;
}
}
?>
<div class="product_right">
<ul class="product_variations_list">
<?php foreach($unique_variations as $variation): ?>
<?php
$meta = get_post_meta($variation['variation_id'], 'attribute_pa_color', true);
if (empty($meta)) {
continue;
}
$term = get_term_by('slug', $meta, 'pa_color');
$color = get_field('product_color', $term->taxonomy . '_' . $term->term_id);
$gallery = get_field('gallery', $variation['variation_id']);
$front_image = wp_get_attachment_image_src($variation['image_id'], 'product-thumbnail')[0];
$back_image = null;
if (!empty($gallery)) {
$back_image = $gallery[0]['sizes']['product-thumbnail'];
}
?>
<li class="<?php echo $variation['variation_id'] == $itemVariation ? 'active' : ''; ?>" data-variation-id="<?php echo $variation['variation_id']; ?>" data-variation-image="<?php echo $front_image; ?>" data-variation-back-image="<?php echo $back_image; ?>">
<a href="<?php echo get_the_permalink(); ?>?attribute_pa_color=<?php echo $term->slug;?>" title="<?php echo $term->name; ?>">
<em class="fas fa-certificate primary" style="color: <?php echo $color ;?>;"></em>
<em class="fas fa-certificate secondary"></em>
</a>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
</div>
<div class="product_bottom">
<ul>
<?php foreach ($attributes as $attribute): ?>
<?php $image = get_field('image', 'pa_specifications_' . $attribute->term_id); ?>
<li>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $attribute->name; ?>">
</li>
<?php endforeach; ?>
</ul>
</div>
</article>
<?php endforeach; ?>
<?php endif;
?>
archive-product.php is not changed :
if ( wc_get_loop_prop( 'total' ) ) {
while ( have_posts() ) {
the_post();
/**
* Hook: woocommerce_shop_loop.
*/
do_action( 'woocommerce_shop_loop' );
wc_get_template_part( 'content', 'product' );
}
}
The code to generate a list of most read articles on my Joomla website AND display their intro images is as follows:
<ul class="mostread<?php echo $moduleclass_sfx; ?>">
<?php foreach ($list as $item) : ?>
<?php $images = json_decode($item->images); ?>
<?php if( $images->image_intro ) : ?>
<img src="<?php echo $images->image_intro; ?>" alt="<?php echo htmlspecialchars($item->title); ?>" />
<?php endif; ?>
<li itemscope itemtype="https://schema.org/Article">
<a href="<?php echo $item->link; ?>" itemprop="url">
<span itemprop="name">
<?php echo $item->title; ?>
</span>
</a>
</li>
<?php endforeach; ?>
</ul>
Having little to no experience with PHP, what do i need to do to this code to make it display only the first item's image instead of for all of them?
#hek-mat was close, but the OP was trying to stop the image on the other posts from displaying, not the link and title.
<?php
// track if we've seen an image yet or not
$seen_first = false;
foreach ( $list as $item ) :
$images = json_decode( $item->images );
// OP only wants posts with image_intros
if ( $images->image_intro ) :
// OP only wants to see the first item's image
if ( ! $seen_first ) :
?>
<img src="<?php echo $images->image_intro; ?>" alt="<?php echo htmlspecialchars( $item->title ); ?>" />
<?php
// don't show another image
$seen_first = true;
// end "if first not seen yet"
endif;
// show the article (for all)
?>
<li itemscope itemtype="https://schema.org/Article">
<a href="<?php echo $item->link; ?>" itemprop="url">
<span itemprop="name"><?php echo $item->title; ?></span>
</a>
</li>
<?php
// end "if image_intro"
endif;
endforeach;
?>
Try like this..
Set a variable $first = true; after displaying first item set it to false.
<ul class="mostread<?php echo $moduleclass_sfx; ?>">
<?php
$first = true;//initially set true
foreach ($list as $item) : ?>
<?php $images = json_decode($item->images); ?>
if($first==true){ ?> //checks $first is true if true prints
<?php if( $images->image_intro ) : ?>
<img src="<?php echo $images->image_intro; ?>" alt="<?php echo htmlspecialchars($item->title); ?>" />
<?php endif;
<li itemscope itemtype="https://schema.org/Article">
<a href="<?php echo $item->link; ?>" itemprop="url">
<span itemprop="name">
<?php echo $item->title; ?>
</span>
</a>
</li>
<?php
}
$first = false;//after printing first item set it false
endforeach; ?>
</ul>
To display only first item image you have do it like below.
<?php
$first = true;//initially set true
foreach ($list as $item) :
$images = json_decode($item->images);
if($first==true):
if( $images->image_intro ) : ?>
<img src="<?php echo $images->image_intro; ?>" alt="<?php echo htmlspecialchars($item->title); ?>" />
<?php
endif;
endif;
$first = false;
?>
<li itemscope itemtype="https://schema.org/Article">
<a href="<?php echo $item->link; ?>" itemprop="url">
<span itemprop="name">
<?php echo $item->title; ?>
</span>
</a>
</li>
<?php endforeach; ?>
Rather than modifying the PHP, it is probably easier to add some CSS to a custom CSS file like this:
ul.mostread img {display: none;}
ul.mostread img:first-of-type {display: block;}
so that only the first image is displayed.
See https://joomla.stackexchange.com/a/3878/120 for instructions on how to create a custom CSS file in Joomla.
A custom CSS file also has the advantage that it won't be overwitten by any future Joomla or template updates.
I have a custom WordPress post type, and want to make so if there are no posts in the query to display, it shows a message of saying no posts were found, I've tried a few suggestions but nothing seems to be working so far.
Full Code of the relevant section:
<?php
$k=0;
$args = array(
'post_type'=>'portfolios',
'posts_per_page'=>5,
'order'=>'DESC'
);
$the_query = new WP_Query($args);
while($the_query->have_posts()):$the_query->the_post();
$k++;
if($k==1){
$color= 'gray';
}else if($k==2){
$color= 'blue';
}else if($k==3){
$color= 'green';
}else if($k==4){
$color= 'light-blue';
}else if($k==5){
$color= 'yellow';
}
?>
<div itemprop="exampleOfWork" class="col-xs-12 col-sm-4 portfolio-item">
<div class="portfolio-holder">
<?php
if(has_post_thumbnail()){
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'singleport',true);
?>
<figure><a itemprop="url" href="<?php the_permalink();?>"><img src="<?php echo $image_url[0];?>" alt="Portfolio image" /></a></figure>
<?php }else{ ?>
<figure><a itemprop="url" href="<?php the_permalink();?>"><img src="<?php echo esc_url( get_template_directory_uri() );?>/assets/images/noimage.jpg" alt="No image" /></a></figure>
<?php } ?>
<h6 itemprop="name"><?php the_title(); ?></h6>
<span itemprop="genre"><?php the_field('name');?></span>
<div class="transparentbg <?php echo $color; ?>">
<?php
$image = get_field('logo');
if( !empty($image) ): ?>
<a itemprop="url" href="<?php the_permalink();?>">
<img src="<?php echo $image['url']; ?>" alt="logo" />
</a>
<?php endif; ?>
<a href="<?php the_permalink();?>" class="info">
<img itemprop="image" src="<?php echo esc_url( get_template_directory_uri() );?>/assets/images/port-hover-bg.png" alt="Port hover bg" /><br />
<img itemprop="image" src="<?php echo esc_url( get_template_directory_uri() );?>/assets/images/search-icon.png" height="20" width="20" alt="Search icon">
</a>
</div>
</div>
</div>
<?php endwhile;wp_reset_query();?>
</div>
</div>
</section>
How can we make it so, if there's no posts, it echo's a message?
Add a check -
if (!empty($the_query->have_posts())) {
while(...) {...}
} else {
echo "No Posts!";
}
Issue
You want to use WP Query class for fetching a particular type of posts ( based on custom fields ), and if it returns no posts at all, it should display a message.
Solution
$the_query = new WP_Query( $args );
Where "$args" is your list of parameters for WP_Query constructor.
Now $the_query is an object of class type WP-Query. Hence it contains a function that will return whether there is any post matching your particular query. If there is at least one post, it will return True, else it will return False.
That function to check if there are any posts matching your queries is have_posts() .
Usage is ObjectName->have_posts();
in your specific case it is
$the_query->have_posts();
This will return true or false based on the query ( ie, arguments you supply using $arg variable ).
hence:
if($the_query->have_posts()) {
//There are posts matching the query
}
else
{
//There are no posts matching the query
}
You can use the below code ( You will have to modify this, but still a good start ).
<?php
$args = array(
'post_type'=>'portfolios',
'posts_per_page'=>5,
'order'=>'DESC'
);
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<!-- pagination here -->
<!-- the loop -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile; ?>
<!-- end of the loop -->
<!-- pagination here -->
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
Reference : https://codex.wordpress.org/Class_Reference/WP_Query
You need to add if condition before while loop like that way:
<?php
$k=0;
$args = array(
'post_type'=>'portfolios',
'posts_per_page'=>5,
'order'=>'DESC'
);
$the_query = new WP_Query($args);
if( $the_query->have_posts() ) {
while($the_query->have_posts()):
// your code
<?php endwhile;
} else {
echo "No data found.";
}
wp_reset_query();
?>
<?php
$k=0;
$args = array(
'post_type'=>'portfolios',
'posts_per_page'=>5,
'order'=>'DESC'
);
$the_query = new WP_Query($args);
if($the_query->have_posts()):
while($the_query->have_posts()):$the_query->the_post();
$k++;
if($k==1){
$color= 'gray';
}else if($k==2){
$color= 'blue';
}else if($k==3){
$color= 'green';
}else if($k==4){
$color= 'light-blue';
}else if($k==5){
$color= 'yellow';
}
?>
<div itemprop="exampleOfWork" class="col-xs-12 col-sm-4 portfolio-item">
<div class="portfolio-holder">
<?php
if(has_post_thumbnail()){
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'singleport',true);
?>
<figure><a itemprop="url" href="<?php the_permalink();?>"><img src="<?php echo $image_url[0];?>" alt="Portfolio image" /></a></figure>
<?php }else{ ?>
<figure><a itemprop="url" href="<?php the_permalink();?>"><img src="<?php echo esc_url( get_template_directory_uri() );?>/assets/images/noimage.jpg" alt="No image" /></a></figure>
<?php } ?>
<h6 itemprop="name"><?php the_title(); ?></h6>
<span itemprop="genre"><?php the_field('name');?></span>
<div class="transparentbg <?php echo $color; ?>">
<?php
$image = get_field('logo');
if( !empty($image) ): ?>
<a itemprop="url" href="<?php the_permalink();?>">
<img src="<?php echo $image['url']; ?>" alt="logo" />
</a>
<?php endif; ?>
<a href="<?php the_permalink();?>" class="info">
<img itemprop="image" src="<?php echo esc_url( get_template_directory_uri() );?>/assets/images/port-hover-bg.png" alt="Port hover bg" /><br />
<img itemprop="image" src="<?php echo esc_url( get_template_directory_uri() );?>/assets/images/search-icon.png" height="20" width="20" alt="Search icon">
</a>
</div>
</div>
</div>
<?php
endwhile;
else:
echo "Your message goes here";
endif;
wp_reset_query();
?>
</div>
</div>
</section>
Adding if condition will do it.
i have this code
<?php $project_taxonomy_select = get_post_meta( $post->ID, '_ep_project_taxonomy_select', true );
$theCatSlug = get_term_by( 'id', $project_taxonomy_select[0], 'project_filter' );
$theCatSlug = $theCatSlug->slug;
echo $theCatSlug; ?>
how to put the php above in "project_filter=" inside my query in the below php code
<div id="project">
<?php $my_query = new WP_Query('post_type=project&posts_per_page=-1&project_filter=the php here');
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<a class="all project-item <?php echo $tax ?>" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<img src="<?php if ( has_post_thumbnail()) { ?><?php $thumb_id = get_post_thumbnail_id(); $thumb_url = wp_get_attachment_image_src($thumb_id,'project-thumb-main', true); echo $thumb_url[0]; ?><?php } else { ?><?php echo esc_url(home_url('/')); ?>assets/img/no-project-thumb-main.jpg<?php } ?>">
<div class="magnifier">
<span class="text"><?php the_title(); ?></span>
</div>
</a>
<?php endwhile; wp_reset_query(); ?>
</div>
im using Custom-Metaboxes-and-Fields-for-WordPress
Please Help.. :)
You'd just use simple string concatentation:
WP_Query('post_type=project&posts_per_page=-1&project_filter='.$theCatSlug);
I have a custom field named "Thumbnail" that I use currently to display thumbnails for my posts on my Wordpress site. I recently bought a new template and can't seem to get the code to display this to work. I think it's because the new template is using an array instead.
Currently, I just have to put:
<img src="<?php echo get_post_meta($post->ID, Thumbnail, true); ?>"/>
and it displays perfectly. So here is the code I believe I need to change in the new site:
<?php if($counter <= $big_count): ?>
<?php if($counter == $big_count) { $last = ‘block-item-big-last’; } else { $last = ”; }?>
<div class="block-item-big <?php echo $last; ?>">
<?php if($images && has_post_thumbnail()): ?>
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), ‘widget-image’); ?>
<div class="block-image"><a href=’<?php the_permalink(); ?>’ title=’<?php the_title(); ?>’><img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" width=’290′ height=’160′ />
Looks like it’s using an array? But I don’t know enough about code to get this to work. I tried to put my code in the img tag of the last line above but pretty sure I need to change something else.
Please help! Thanks.
**UPDATE**
Thanks for the info #Ehs4n and #Tim! Still no luck but I decided to try a simpler approach by removing that part of the code that checks for the array. I feel like I am close. Here is what I have now.
<?php if (in_category('movies') ): ?>
<div class="block-item-big-<?php echo $last; ?>">
<div class="block-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php echo get_post_meta($post->ID, Thumbnail, true); ?>" alt="<?php the_title(); ?>"/></a><?php echo $icon; ?></div>
But the still no thumbnail shows up? Not sure what I am missing, I have a Custom Field called Thumbnail with the appropriate link to the picture on the server on that post. It even works correctly when I put in the actual URL in for the img src to that picture but when I put in the code...
<?php echo get_post_meta($post->ID, Thumbnail, true); ?>
it is like it does not understand that. Firebug tells me that the src is empty, it is like it is not returning Thumbnail Custom Field as it should be?
Below is the entire file which is an include via a Widget to display a category layout on the index of the site.
<?php
add_action('widgets_init', 'pyre_homepage_1col_load_widgets');
function pyre_homepage_1col_load_widgets()
{
register_widget('Pyre_Homepage_1col_Widget');
}
class Pyre_Homepage_1col_Widget extends WP_Widget {
function Pyre_Homepage_1col_Widget()
{
$widget_ops = array('classname' => 'pyre_homepage_1col', 'description' => 'Homepage 1-column recent posts widget.');
$control_ops = array('id_base' => 'pyre_homepage_1col-widget');
$this->WP_Widget('pyre_homepage_1col-widget', 'Avenue Theme: Home 1-column', $widget_ops, $control_ops);
}
function widget($args, $instance)
{
extract($args);
$title = $instance['title'];
$post_type = 'all';
$categories = $instance['categories'];
$posts = $instance['posts'];
$images = true;
$rating = true;
$show_excerpt = isset($instance['show_excerpt']) ? 'true' : 'false';
echo $before_widget;
?>
<?php
$post_types = get_post_types();
unset($post_types['page'], $post_types['attachment'], $post_types['revision'], $post_types['nav_menu_item']);
if($post_type == 'all') {
$post_type_array = $post_types;
} else {
$post_type_array = $post_type;
}
?>
<div class="block full">
<h3><?php echo $title; ?> <span class="arrows">»</span></h3>
<?php
$recent_posts = new WP_Query(array(
'showposts' => $posts,
'cat' => $categories,
));
?>
<?php
$big_count = round($posts / 4);
if(!$big_count) { $big_count = 1; }
?>
<?php $counter = 1; while($recent_posts->have_posts()): $recent_posts->the_post(); ?>
<?php
if(has_post_format('video') || has_post_format('audio') || has_post_format('gallery')) {
$icon = '<span class="' . get_post_format($post->ID) . '-icon"></span>';
} else {
$icon = '';
}
?>
<?php if($counter <= $big_count): ?>
<?php if($counter == $big_count) { $last = 'block-item-big-last'; } else { $last = ''; }?>
<!-- Movies Category -->
<?php if (in_category('movies') ): ?>
<div class="block-item-big-Movies <?php echo $last; ?>">
<div class="block-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?> movie review'><img src="<?php echo get_post_meta($post->ID, Thumbnail, true); ?>"/></a><?php echo $icon; ?></div>
<h2><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?> movie review'><?php the_title(); ?></a></h2>
<span class="block-meta"><?php the_time('F j, Y'); ?>, <?php comments_popup_link(); ?></span>
<?php if($show_excerpt == 'true'): ?><p><?php echo string_limit_words(get_the_excerpt(), 15); ?> ...</p><?php endif; ?>
</div>
<!-- END Movies Category -->
<!-- Music Category -->
<?php elseif (in_category('music') ): ?>
<div class="block-item-big <?php echo $last; ?>">
<?php if($images && has_post_thumbnail()): ?>
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'widget-image'); ?>
<div class="block-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" width='290' height='160' /></a><?php echo $icon; ?></div>
<?php else: ?>
<div class="block-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php bloginfo('template_directory'); ?>/images/thumbnail.png&w=290&h=160" alt="<?php the_title(); ?>" width='290' height='160' /></a><?php echo $icon; ?></div>
<?php endif; ?>
<h2><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_title(); ?></a></h2>
<span class="block-meta"><?php the_time('F j, Y'); ?>, <?php comments_popup_link(); ?></span>
<?php if($show_excerpt == 'true'): ?><p><?php echo string_limit_words(get_the_excerpt(), 15); ?> ...</p><?php endif; ?>
</div>
<!-- END Music Category -->
<!-- Else Default Display -->
<?php else: ?>
<div class="block-item-big <?php echo $last; ?>">
<?php if($images && has_post_thumbnail()): ?>
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'widget-image'); ?>
<div class="block-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" width='290' height='160' /></a><?php echo $icon; ?></div>
<?php else: ?>
<div class="block-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php bloginfo('template_directory'); ?>/images/thumbnail.png&w=290&h=160" alt="<?php the_title(); ?>" width='290' height='160' /></a><?php echo $icon; ?></div>
<?php endif; ?>
<h2>MUSIC<a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_title(); ?></a></h2>
<span class="block-meta"><?php the_time('F j, Y'); ?>, <?php comments_popup_link(); ?></span>
<?php if($show_excerpt == 'true'): ?><p><?php echo string_limit_words(get_the_excerpt(), 15); ?> ...</p><?php endif; ?>
</div>
<!-- END Normal Display -->
<?php endif; ?>
<?php else: ?>
<div class="block-item-small">
<?php if($images && has_post_thumbnail()): ?>
<?php $image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'widget-image-thumb'); ?>
<div class="block-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php echo $image[0]; ?>" alt="<?php the_title(); ?>" width='50' height='50' /></a><?php echo $icon; ?></div>
<?php else: ?>
<div class="block-image"><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php bloginfo('template_directory'); ?>/images/thumbnail.png&w=50&h=50" alt="<?php the_title(); ?>" width='50' height='50' /></a><?php echo $icon; ?></div>
<?php endif; ?>
<h2><a href='<?php the_permalink(); ?>' title='<?php the_title(); ?>'><?php the_title(); ?></a></h2>
<span class="block-meta"><?php the_time('F j, Y'); ?>, <?php comments_popup_link(); ?></span>
</div>
<?php endif; ?>
<?php $counter++; endwhile; ?>
</div>
<?php
echo $after_widget;
}
function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance['title'] = $new_instance['title'];
$instance['post_type'] = 'all';
$instance['categories'] = $new_instance['categories'];
$instance['posts'] = $new_instance['posts'];
$instance['show_images'] = true;
$instance['show_rating'] = true;
$instance['show_excerpt'] = $new_instance['show_excerpt'];
return $instance;
}
function form($instance)
{
$defaults = array('title' => 'Recent Posts', 'post_type' => 'all', 'categories' => 'all', 'posts' => 4, 'show_excerpt' => null);
$instance = wp_parse_args((array) $instance, $defaults); ?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>">Title:</label>
<input class="widefat" style="width: 216px;" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('categories'); ?>">Filter by Category:</label>
<select id="<?php echo $this->get_field_id('categories'); ?>" name="<?php echo $this->get_field_name('categories'); ?>" class="widefat categories" style="width:100%;">
<option value='all' <?php if ('all' == $instance['categories']) echo 'selected="selected"'; ?>>all categories</option>
<?php $categories = get_categories('hide_empty=0&depth=1&type=post'); ?>
<?php foreach($categories as $category) { ?>
<option value='<?php echo $category->term_id; ?>' <?php if ($category->term_id == $instance['categories']) echo 'selected="selected"'; ?>><?php echo $category->cat_name; ?></option>
<?php } ?>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id('posts'); ?>">Number of posts:</label>
<input class="widefat" style="width: 30px;" id="<?php echo $this->get_field_id('posts'); ?>" name="<?php echo $this->get_field_name('posts'); ?>" value="<?php echo $instance['posts']; ?>" />
</p>
<p>
<input class="checkbox" type="checkbox" <?php checked($instance['show_excerpt'], 'on'); ?> id="<?php echo $this->get_field_id('show_excerpt'); ?>" name="<?php echo $this->get_field_name('show_excerpt'); ?>" />
<label for="<?php echo $this->get_field_id('show_excerpt'); ?>">Show excerpt</label>
</p>
<?php }
}
?>
Throw in a print_r($image) to find out if Image is an array. What result is coming out of using image[0]?
If you are using custom fields to store thumbnail paths, why are you confused with the code used in your template.
You can still use your old code to get the image
<?php echo get_post_meta($post->ID, Thumbnail, true); ?>
Looking at your template's code, it uses Wordpress function wp_get_attachment_image_src() which takes three parameters, $attachement_id - to pass id of that media, $size - media size / image size to display & third optional $icon to display an icon to represent the attachment. Here you are passing $attachment_id of the image set as your post thumbnail in the post and the size. The function in turn returns an array containing url, width and height, url being the first one, so using $image[0] will return the url of the image, which is fine.
If the image is still not being displayed, you need to confirm whether you have attached image as post thumbnail in your post and that the $images variable returns true on if clause.