Hi All,
I’m taking my first steps into php though WordPress, and although i seem to be about 90% of the way there in terms of where i would like the site to be, i just have a couple of final issues that i just can’t work out. To help me along the way i have used a few templates, which I’ve been able to customize to suit my needs.
I’m not sure how much detail i need to provided, but below is the php from the relevant widget page. What I’m after is to only show certain listings so for example i have it set up so you can specify if the car is sold or not. For this widget i only want to show the available cars. As i understand i need to include a statement within the ‘$args’ which specifies to only include listings with the status of available - but i have no idea as to how this would be done.
Hopefully this has made some sense and it’s possible to either point me in the right direction or show how the code would look. Also if i have missed any aspect this would need to be provided please let me know and i will upload.
Many thanks,
Keith
<?php
class ct_Listings extends WP_Widget {
function ct_Listings() {
$widget_ops = array('description' => 'Display your latest listings.' );
parent::WP_Widget(false, __('Listings', 'contempo'),$widget_ops);
}
function widget($args, $instance) {
extract( $args );
$title = $instance['title'];
$number = $instance['number'];
$taxonomy = $instance['taxonomy'];
$viewalltext = $instance['viewalltext'];
$viewalllink = $instance['viewalllink'];
?>
<?php echo $before_widget; ?>
<?php if ($title) { echo $before_title . $title . $after_title; }
echo '<ul>';
global $post;
query_posts(array(
'post_type' => 'listings',
'order' => 'DSC',
$taxonomy => $tag,
'posts_per_page' => $number
));
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li>
<div class="img-wrap columns left">
<?php ct_status(); ?>
<?php ct_first_image_tn_left(); ?>
</div>
<div class="eight columns marL10 left">
<h6><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h6>
<p class="price"><strong><?php currency(); ?><?php listing_price(); ?></strong></p>
<p class="propinfo"><?php if( (get_post_meta($post->ID, "_ct_mileage", true)) != 0 ) { ?><?php echo get_post_meta($post->ID, "_ct_mileage", true); ?><?php } ?> <?php _e('miles', 'contempo'); ?><br />
<?php extcolor(); ?> / <?php intcolor(); ?></p>
</div>
<div class="clear"></div>
</li>
<?php endwhile; endif; wp_reset_query(); ?>
<?php echo '</ul>'; ?>
<?php if($viewalltext) { ?>
<p id="viewall"><a class="read-more right" href="<?php echo $viewalllink; ?>"><?php echo $viewalltext; ?> <em>→</em></a></p>
<?php } ?>
<?php echo $after_widget; ?>
<?php
}
function update($new_instance, $old_instance) {
return $new_instance;
}
function form($instance) {
$title = esc_attr($instance['title']);
$number = esc_attr($instance['number']);
$taxonomy = esc_attr($instance['taxonomy']);
$tag = esc_attr($instance['tag']);
$viewalltext = esc_attr($instance['viewalltext']);
$viewalllink = esc_attr($instance['viewalllink']);
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:','contempo'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('number'); ?>"><?php _e('Number:','contempo'); ?></label>
<select name="<?php echo $this->get_field_name('number'); ?>" class="widefat" id="<?php echo $this->get_field_id('number'); ?>">
<?php for ( $i = 1; $i <= 10; $i += 1) { ?>
<option value="<?php echo $i; ?>" <?php if($number == $i){ echo "selected='selected'";} ?>><?php echo $i; ?></option>
<?php } ?>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id('taxonomy'); ?>"><?php _e('Taxonomy:','contempo'); ?></label>
<select name="<?php echo $this->get_field_name('taxonomy'); ?>" class="widefat" id="<?php echo $this->get_field_id('taxonomy'); ?>">
<?php
foreach (get_object_taxonomies( 'listings', 'objects' ) as $tax => $value) { ?>
<option value="<?php echo $tax; ?>" <?php if($taxonomy == $tax){ echo "selected='selected'";} ?>><?php echo $tax; ?></option>
<?php } ?>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id('tag'); ?>"><?php _e('Tag:','contempo'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('tag'); ?>" value="<?php echo $tag; ?>" class="widefat" id="<?php echo $this->get_field_id('tag'); ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('viewalltext'); ?>"><?php _e('View All Link Text','contempo'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('viewalltext'); ?>" value="<?php echo $viewalltext; ?>" class="widefat" id="<?php echo $this->get_field_id('viewalltext'); ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('viewalllink'); ?>"><?php _e('View All Link URL','contempo'); ?></label>
<input type="text" name="<?php echo $this->get_field_name('viewalllink'); ?>" value="<?php echo $viewalllink; ?>" class="widefat" id="<?php echo $this->get_field_id('viewalllink'); ?>" />
</p>
<?php
}
}
register_widget('ct_Listings');
?>