Changeset 588461
- Timestamp:
- 08/21/2012 05:30:11 PM (13 years ago)
- File:
-
- 1 edited
-
posts-in-page/trunk/posts_in_page.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
posts-in-page/trunk/posts_in_page.php
r588108 r588461 4 4 Author: dgilfoy, ivycat, sewmyheadon 5 5 Description: Easily add one or more posts to any page using simple shortcodes. Supports categories, tags, custom post types, custom taxonomies, and more. 6 Version: 1.0. 46 Version: 1.0.5 7 7 8 8 Shortcode usage: … … 19 19 **/ 20 20 21 define( 'POSTSPAGE_DIR', dirname( __FILE__ ) ); 22 define( 'POSTPAGE_URL', str_replace( ABSPATH, site_url(), POSTSPAGE_DIR ) ); 23 21 24 class AddPostsToPage{ 22 25 … … 26 29 add_shortcode( 'ic_add_posts', array( &$this, 'posts_in_page' ) ); 27 30 add_shortcode( 'ic_add_post', array( &$this, 'post_in_page' ) ); 31 add_action( 'admin_menu', array( &$this, 'plugin_page_init' ) ); 28 32 } 29 33 … … 31 35 extract( shortcode_atts( array( 32 36 'category' => false, 37 'cats' => false, 33 38 'post_type' => false, 34 39 'tax' => false, … … 43 48 self::set_args( $atts ); 44 49 return self::output_posts(); 50 } 51 52 public function plugin_page_init(){ 53 if( !current_user_can( 'administrator' ) ) return; 54 $hooks = array(); 55 $hooks[] = add_options_page( __( 'Posts In Page' ), __( 'Posts In Page' ), 'read', 'posts_in_page', 56 array( $this, 'plugin_page') ); 57 foreach($hooks as $hook) { 58 add_action("admin_print_styles-{$hook}", array($this, 'load_assets')); 59 } 60 } 61 62 public function load_assets(){ 63 wp_enqueue_style( 'postpagestyle', POSTPAGE_URL. '/assets/postpagehelp.css' ); 64 } 65 66 public function plugin_page(){ 67 require_once 'assets/posts_in_page_help_view.php'; 45 68 } 46 69 … … 57 80 public function post_in_page( $atts ){ 58 81 $args = array( 'post_type' => ( $atts['post_type'] ) ? $atts['post_type'] : 'post' ); 59 if( $atts['id'] ) $args['post_in'] = array( $atts['id'] ); 60 $args['posts_per_page'] = 1; 82 if( $atts['id'] ) { 83 $ids = explode( ',', $atts['id'] ); 84 if( count( $ids ) > 1 ): 85 $args['post__in'] = $ids; 86 $args['posts_per_page'] = count( $ids ); 87 else: 88 $args['p'] = $atts['id']; 89 $args['posts_per_page'] = 1; 90 endif; 91 } 92 61 93 $page_posts = new WP_Query( $args ); 94 //fprint_r( $page_posts ); 62 95 $output = ''; 63 96 if( $page_posts->have_posts() ): while( $page_posts->have_posts()): … … 73 106 if($atts['ids'] ){ 74 107 $post_ids = explode( ',', $atts['ids'] ); 75 $this->args['post_ in'] = $post_ids;108 $this->args['post__in'] = $post_ids; 76 109 $this->args['posts_per_page'] = count( $post_ids ); 77 110 } … … 84 117 $cats = explode( ',', $atts['category'] ); 85 118 $this->args['category_name'] = ( count( $cats ) > 1 ) ? $cats : $atts['category']; 119 }elseif( $atts['cats'] ){ 120 $cats = explode( ',', $atts['cats'] ); 121 $this->args['category_name'] = ( count( $cats ) > 1 ) ? $cats : $atts['cats']; 86 122 } 87 123 if( $atts['tax'] ){
Note: See TracChangeset
for help on using the changeset viewer.