Source code for /home/gipetto1/top-frog.com/public_html/script_src/files/my-featured-posts.php
- <?php
-
- http://denver.wordcamp.org
- http://denver.wordcamp.org
-
-
-
-
-
- add_action('admin_init','mfp_admin_init');
-
-
-
- function mfp_admin_init() {
-
-
- add_meta_box('featured-post','FEATURED POST', 'mfp_meta_box','post','side','default');
-
- add_action('save_post','mfp_save_post');
- }
-
-
- @param
- @param
- function mfp_meta_box($post,$box) {
-
-
- @NOTE
- http://us3.php.net/manual/en/language.types.object.php
- $featured = get_post_meta($post->ID,'_mfp_is_featured',true);
-
-
- echo '
- <p class="meta_options">
- <label for="mfp_featured_post"><select name="mfp_featured_post" id="mfp_featured_post">
- <option value="0" '.(is_null($featured) || $featured == '0' ? 'selected="selected" ' : '').
- '>Not Featured</option>
- <option value="1" '.($featured == '1' ? 'selected="selected" ' : '').
- '>Feature this post</option>
- </select>
- </p>
- ';
-
- http://us2.php.net/manual/en/language.operators.comparison.php
- }
-
-
- @param
- @param
- function mfp_save_post($post_id,$post) {
-
-
- if($post->post_type == 'revision') { return; }
-
-
-
-
- if(isset($_POST['mfp_featured_post'])) {
-
-
- update_post_meta($post_id,'_mfp_is_featured',$_POST['mfp_featured_post']);
- }
- }
-
-
-
- add_filter('the_title','mfp_the_title');
-
-
- @param
- @return
- function mfp_the_title($the_title) {
-
-
- global $post;
-
-
-
- if(in_the_loop()) {
-
- $featured = get_post_meta($post->ID,'_mfp_is_featured',true);
- if($featured == '1') {
-
- $the_title = '<span class="mfp-featured">[FEATURED POST] </span>'.$the_title;
- }
- }
-
- return $the_title;
- }
-
-
-
- add_action('widgets_init','mfp_widgets_init');
-
-
- function mfp_widgets_init() {
-
- wp_register_sidebar_widget('mfp-widget','My Featured Post', 'mfp_widget');
- }
-
-
- @param
- @return
- function mfp_widget($args) {
-
- extract($args);
-
-
-
-
-
- echo $before_widget.
- $before_title.'My Featured Posts'.$after_title.
- mfp_featured_posts_list(5).
- $after_widget;
- }
-
-
- @param
- @return
- function mfp_get_featured_posts($showposts=5) {
-
-
- $queryObject = new WP_Query(array(
- 'showposts' => $showposts,
- 'meta_key' => '_mfp_is_featured',
- 'meta_value' => '1'
- ));
- @NOTE
-
- return $queryObject->posts;
- }
-
-
- @param
- @param
- @return
- function mfp_featured_posts_list($showposts,$id='mfp-featured-posts-list') {
-
- $featured_posts = mfp_get_featured_posts($showposts);
-
-
- $html = '<ul id="'.$id.'">';
-
-
-
- if(count($featured_posts)) {
- foreach($featured_posts as $fp) {
-
-
-
- $html .= '<li><a href="'.get_permalink($fp->ID).'">'.apply_filters('the_title',$fp->post_title).'</a></li>';
- @NOTE
- }
- }
- else {
-
- $html .= '<li>There are no featured posts at this time.</li>';
- }
- $html .= '</ul>';
-
-
- return $html;
- }
-
-
-
-
- add_filter('the_content','mfp_the_content');
-
-
- @param
- @return
- function mfp_the_content($the_content) {
-
- if(is_single()) {
-
- $the_content .= '<div id="more-featured-posts">
- <h2>Other Featured Posts</h2>
- '.mfp_featured_posts_list(10,'more-featured-posts-list').
- '
- </div>
- ';
- }
-
- return $the_content;
- }
- ?>