/** * Generate the output for the featured list * @return string */ function fpk_featured_list($full = true) { /** * Get Featured list from options table */ $featured = featured_posts_list_get_options_stored(); /** * Display the featured list */ if ($featured) { $output = $full ? '<ul class="featured-posts-list">' : ''; foreach ($featured as $postId) { $output .= '<li>'; $output .= '<a href="' . get_permalink($postId) . '">' . get_the_title($postId) . '</a>'; $output .= '</li>'; } $output .= $full ? '</ul>' : ''; } return $output; }
function featured_posts_list_admin_page() { $option_name = 'featured_posts_list'; /** * Check permissions for admin page */ if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.')); } /** * If POST twitter_linkedin_kindle_share_position */ if (isset($_POST['Submit'])) { if (isset($_POST['featured']) && count($_POST['featured']) > 0) { $list = array(); foreach ($_POST['featured'] as $id) { $list[] = (int) $id; } update_option($option_name, $list); echo '<div class="updated"><p><strong>' . __('Featured List Saved.', 'menu-test') . '</strong></p></div>'; } } $posts = get_posts(array('post_type' => 'post', 'numberposts' => -1)); $featured = featured_posts_list_get_options_stored(); ?> <div class="wrap"> <?php screen_icon(); ?> <h2><?php echo __('Featured Posts List', 'menu-test'); ?> </h2> <div id="poststuff" style="padding-top:10px; position:relative;"> <div style="float:left; width:74%; padding-right:1%;"> <form name="form1" method="post" action=""> <div class="postbox"> <h3><?php echo __("Select Featured Posts", 'menu-test'); ?> </h3> <div class="inside"> <table class="optiontable form-table"> <?php foreach ($posts as $post) { if (is_array($featured)) { $selected = in_array($post->ID, $featured) ? 'checked="checked"' : ''; } else { $selected = ''; } ?> <tr> <td style="width:20px;"><input type="checkbox" value="<?php echo $post->ID; ?> " name="featured[]" <?php echo $selected; ?> /></td> <td><strong><?php echo $post->post_title; ?> </strong></td> </tr> <?php } ?> </table> </div> </div> <p class="submit"> <input type="submit" name="Submit" class="button-primary" value="<?php echo esc_attr('Save Changes'); ?> " /> </p> </form> </div> </div> </div> <?php }