Skip to content

Instantly share code, notes, and snippets.

@atinder
Created March 31, 2013 03:26
Show Gist options
  • Save atinder/5279416 to your computer and use it in GitHub Desktop.
Save atinder/5279416 to your computer and use it in GitHub Desktop.
cleanography widgets updated
<?php
/**** WIDGETS AREA ****/
/* *****************************************************
* Plugin Name: Cleanography Recent Posts
* Description: Display Recent Posts with Thumbs.
* Version: 1.0
* Author: Atinder
* Author URI: http://www.atinder.com
* ************************************************** */
class al_recent_widget extends WP_Widget {
// Widget setup.
function al_recent_widget() {
// Widget settings.
$widget_ops = array(
'classname' => 'widget_al_recent',
'description' => __( 'Display Recent Posts', 'Cleanography' )
);
// Widget control settings.
$control_ops = array(
'width' => 109,
'height' => 106,
'id_base' => 'al-recent-widget'
);
// Create the widget.
$this->WP_Widget( 'al-recent-widget', __( 'Cleanography Recent Posts', 'al_recent' ) , $widget_ops, $control_ops );
}
// Display the widget on the screen.
function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
$nr = ( $instance['posts_nr'] != '' ) ? $nr = $instance['posts_nr'] : $nr = 6;
echo $before_widget;
if ( $title ) echo $before_title . $title . $after_title;
$query = 'orderby=comment_count&showposts=' . $nr;
$query = (isset($instance['cat']) && $instance['cat']!='') ? $query . '&category_name=' . $instance['cat'] : $query;
$recent = new WP_Query( $query );
// $recent->query( 'showposts=' . $nr );
$rcount = 0;
while ( $recent->have_posts() ) : $recent->the_post();
$rcount++;
echo '<div class="post"> <a href="' . get_permalink() . '">';
the_post_thumbnail( 'recent-post-thumb', array( 'class' => 'p-thumb' ) );
echo '</a>';
echo '<h6><a href="' . get_permalink() . '">' . get_the_title() . '</a></h6>';
echo '<p>' . limit_words( get_the_excerpt(), '6' ) . '</p>';
echo '<span class="date">' . get_the_date() . '</span> </div>';
if($rcount!=$nr){
echo '<div class="f-sep"> </div>';
}
endwhile;
echo '<div class="clear"></div>'.$after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['posts_nr'] = strip_tags( $new_instance['posts_nr'] );
$instance['cat'] = strip_tags( $new_instance['cat'] );
return $instance;
}
function form( $instance ) {
$defaults = array(
'title' => 'Recent Posts',
'posts_nr' => '4',
'cat' => ''
);
$instance = wp_parse_args( (array)$instance, $defaults ); ?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'cleanography' ); ?></label>
<input id="<?php echo $this->get_field_id( 'title' ); ?>" type="text" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" class="widefat" />
</p>
<p>
<label for="<?php echo $this->get_field_id( 'posts_nr' ); ?>">Number of posts</label>
<input id="<?php echo $this->get_field_id( 'posts_nr' ); ?>" type="text" name="<?php echo $this->get_field_name( 'posts_nr' ); ?>" value="<?php echo $instance['posts_nr']; ?>" class="widefat" />
</p>
<p>
<label for="<?php echo $this->get_field_id( 'cat' ); ?>">Number of posts</label>
<select id="<?php echo $this->get_field_id( 'cat' ); ?>" name="<?php echo $this->get_field_name( 'cat' ); ?>" style="width:100%;">
<?php foreach ($this->getCats() as $key => $value) { ?>
<option value="<?php echo $value; ?>" <?php selected($instance['cat'],$value);?>><?php echo $value; ?></option>
<?php } ?>
</select>
</p>
<?php
}
function getCats(){
//Access the WordPress Categories via an Array
$categories = array();
$categories_obj = get_categories('hide_empty=0');
foreach ($categories_obj as $of_cat) {
$categories[$of_cat->cat_ID] = $of_cat->slug;}
$categories_tmp = array_unshift($categories, "Select a category:");
return $categories;
}
}
register_widget( 'al_recent_widget' );
/* *****************************************************
* Plugin Name: Cleanography Popular Posts
* Description: Display Popular Posts with Thumbs.
* Version: 1.0
* Author: Atinder
* Author URI: http://www.Atinder.com
* ************************************************** */
class al_popular_widget extends WP_Widget {
// Widget setup.
function al_popular_widget() {
// Widget settings.
$widget_ops = array(
'classname' => 'widget_al_popular',
'description' => __( 'Display Popular Posts', 'Cleanography' )
);
// Widget control settings.
$control_ops = array(
'width' => 109,
'height' => 106,
'id_base' => 'al-popular-widget'
);
// Create the widget.
$this->WP_Widget( 'al-popular-widget', __( 'Cleanography Popular Posts', 'al_popular' ) , $widget_ops, $control_ops );
}
// Display the widget on the screen.
function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
$nr = ( $instance['posts_nr'] != '' ) ? $nr = $instance['posts_nr'] : $nr = 6;
echo $before_widget;
if ( $title ) echo $before_title . $title . $after_title;
$popular = new WP_Query( 'orderby=comment_count&showposts=' . $nr );
while ( $popular->have_posts() ) : $popular->the_post();
echo '<div class="pop-posts"> <a href="' . get_permalink() . '">';
the_post_thumbnail( 'popular-post-thumb', array( 'class' => 'p-thumb' ) );
echo '</a>';
echo '<p class="p-title"> <a href="'. get_permalink() . '">' . get_the_title() . '</a> </p>';
echo '<p>' . limit_words( get_the_excerpt(), '6' ) . '</p> </div>';
endwhile;
echo '<div class="clear"></div>'.$after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['posts_nr'] = strip_tags( $new_instance['posts_nr'] );
return $instance;
}
function form( $instance ) {
$defaults = array(
'title' => 'popular Posts',
'posts_nr' => '4'
);
$instance = wp_parse_args( (array)$instance, $defaults ); ?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'cleanography' ); ?></label>
<input id="<?php echo $this->get_field_id( 'title' ); ?>" type="text" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" class="widefat" />
</p>
<p>
<label for="<?php echo $this->get_field_id( 'posts_nr' ); ?>">Number of posts</label>
<input id="<?php echo $this->get_field_id( 'posts_nr' ); ?>" type="text" name="<?php echo $this->get_field_name( 'posts_nr' ); ?>" value="<?php echo $instance['posts_nr']; ?>" class="widefat" />
</p>
<?php
}
}
register_widget( 'al_popular_widget' );
/* *****************************************************
* Plugin Name: Cleanography Testimonials
* Description: Display testimonials.
* Version: 1.0
* Author: Atinder
* Author URI: http://www.Atinder.com
* ************************************************** */
class al_testimonial_widget extends WP_Widget {
// Widget setup.
function al_testimonial_widget() {
// Widget settings.
$widget_ops = array(
'classname' => 'widget_al_testimonial',
'description' => __( 'Display client testimonials', 'Cleanography' )
);
// Widget control settings.
$control_ops = array(
'width' => 109,
'height' => 106,
'id_base' => 'al-testimonial-widget'
);
// Create the widget.
$this->WP_Widget( 'al-testimonial-widget', __( 'Cleanography client testimonials', 'al_testimonial' ) , $widget_ops, $control_ops );
}
// Display the widget on the screen.
function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
$nr = ( $instance['posts_nr'] != '' ) ? $nr = $instance['posts_nr'] : $nr = 6;
echo $before_widget;
if ( $title ) echo $before_title . $title . $after_title;
echo '<div id="testimonials1">';
$testimonial = new WP_Query( 'post_type=testimonials&orderby=post_date&order=desc&showposts=' . $nr );
while ( $testimonial->have_posts() ) : $testimonial->the_post();
echo '<blockquote><p>';
echo get_the_content() . '<cite>' . get_the_title() . '</cite></p></blockquote>';
endwhile;
echo '</div><div class="clear"></div>'.$after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['posts_nr'] = strip_tags( $new_instance['posts_nr'] );
return $instance;
}
function form( $instance ) {
$defaults = array(
'title' => 'Client Testimonial',
'posts_nr' => '3'
);
$instance = wp_parse_args( (array)$instance, $defaults ); ?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'cleanography' ); ?></label>
<input id="<?php echo $this->get_field_id( 'title' ); ?>" type="text" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" class="widefat" />
</p>
<p>
<label for="<?php echo $this->get_field_id( 'posts_nr' ); ?>">Number of posts</label>
<input id="<?php echo $this->get_field_id( 'posts_nr' ); ?>" type="text" name="<?php echo $this->get_field_name( 'posts_nr' ); ?>" value="<?php echo $instance['posts_nr']; ?>" class="widefat" />
</p>
<?php
}
}
register_widget( 'al_testimonial_widget' );
/* *****************************************************
* Plugin Name: Last Tweets
* Description: Displays Latest Tweets.
* Version: 1.1
* Author: Atinder
* Author URI: http://www.Atinder.com
* ************************************************** */
add_action( 'widgets_init', 'es_tweets_widgets' );
function es_tweets_widgets() {
register_widget( 'ES_Tweet_Widget' );
}
class es_tweet_widget extends WP_Widget {
function ES_Tweet_Widget() {
$widget_ops = array( 'classname' => 'es_tweet_widget', 'description' => __( 'A custom widget for displaying your latest tweets.', 'Cleanography' ) );
$this->WP_Widget( 'es_tweet_widget', __( 'Cleanography Latest Tweets', 'Cleanography' ), $widget_ops );
}
function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
$username = $instance['username'];
$postcount = $instance['postcount'];
echo $before_widget;
if ( $title )
echo $before_title . $title . '<span class="twitbird">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>'.$after_title;
?>
<div class="demo">
<pre class="code">
jQuery(function($){ $(&quot;.tweet&quot;).tweet({ join_text: &quot;auto&quot;, username: &quot;<?php echo $username; ?>&quot;, avatar_size: 48, count: <?php echo $postcount;?>, auto_join_text_default: &quot;we said,&quot;, auto_join_text_ed: &quot;we&quot;, auto_join_text_ing: &quot;we were&quot;, auto_join_text_reply: &quot;we replied&quot;, auto_join_text_url: &quot;we were checking out&quot;, loading_text: &quot;loading tweets...&quot; }); });
</pre>
<div class='tweet query'> </div>
</div>
<?php
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['username'] = strip_tags( $new_instance['username'] );
$instance['postcount'] = strip_tags( $new_instance['postcount'] );
return $instance;
}
function form( $instance ) {
$defaults = array(
'title' => 'Latest Tweets',
'username' => 'atinder90',
'postcount' => '5',
'tweettext' => 'Follow on Twitter',
);
$instance = wp_parse_args( (array) $instance, $defaults ); ?>
<div>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'Cleanography' ) ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" />
</div>
<div>
<label for="<?php echo $this->get_field_id( 'username' ); ?>"><?php _e( 'Twitter Username (e.g., Atinder)', 'Cleanography' ) ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'username' ); ?>" name="<?php echo $this->get_field_name( 'username' ); ?>" value="<?php echo $instance['username']; ?>" />
</div>
<div>
<label for="<?php echo $this->get_field_id( 'postcount' ); ?>"><?php _e( 'Number of tweets (Keep < 20)', 'Cleanography' ) ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'postcount' ); ?>" name="<?php echo $this->get_field_name( 'postcount' ); ?>" value="<?php echo $instance['postcount']; ?>" />
</div>
<?php
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment