0byt3m1n1
Path:
/
home1
/
aserty
/
public_html
/
appartsoft.info
/
wp-content
/
plugins
/
random-mage
/
[
Home
]
File: random-mage.php
<?php /* Plugin Name: Random Post Mage Plugin URI: http://www.wpmage.com Description: Generates a widget containing a list of random posts titles/links Version: 1.0.2 Author: Wordpress Mage Author URI: http://www.wpmage.com */ class RandomPostMage extends WP_Widget { function RandomPostMage() { parent::WP_Widget(false, $name = 'Random Post Mage'); } function grab_random_posts() { global $wpdb; $postData = array(); $countsql = "SELECT COUNT(*) AS noPosts FROM " . $wpdb->posts . " WHERE post_type='post' AND post_title != '' AND post_status = 'publish'"; $noPostsObj = $wpdb->get_results ( $countsql, ARRAY_A ); $noPosts = $noPostsObj [0] ['noPosts']; if (! $noPosts) { return $postData; } $sql = "SELECT post_name,post_title,ID FROM " . $wpdb->posts . " WHERE post_type='post' AND post_title != '' AND post_status='publish' ORDER BY RAND() LIMIT 10"; $postData = $wpdb->get_results ( $sql ); return $postData; } /** @see WP_Widget::widget */ function widget($args, $instance) { extract( $args ); $title = apply_filters('widget_title', $instance['title']); echo $before_widget; if ( $title ) echo $before_title . $title . $after_title; $randomPosts = $this->grab_random_posts(); if(count($randomPosts) > 0) { echo "<ul>"; foreach($randomPosts as $randomPost) { $permalink = NULL; $permalink = get_permalink ( $randomPost->ID ); echo "<li>"; echo '<a href="'.$permalink.'">'; echo $randomPost->post_title; echo "</a>"; echo "</li>"; } echo "</ul>"; } echo $after_widget; } /** @see WP_Widget::update */ function update($new_instance, $old_instance) { return $new_instance; } /** @see WP_Widget::form */ function form($instance) { $title = esc_attr($instance['title']); ?> <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></label></p> <?php } } add_action('widgets_init', create_function('', 'return register_widget("RandomPostMage");'));