Plugin Directory

Changeset 588461


Ignore:
Timestamp:
08/21/2012 05:30:11 PM (13 years ago)
Author:
dgilfoy
Message:

fixed an issue with adding a single or specific posts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • posts-in-page/trunk/posts_in_page.php

    r588108 r588461  
    44    Author: dgilfoy, ivycat, sewmyheadon
    55    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.4
     6    Version: 1.0.5
    77   
    88   Shortcode usage:
     
    1919**/
    2020
     21define( 'POSTSPAGE_DIR', dirname( __FILE__ ) );
     22define( 'POSTPAGE_URL', str_replace( ABSPATH, site_url(), POSTSPAGE_DIR ) );
     23
    2124class AddPostsToPage{
    2225   
     
    2629        add_shortcode( 'ic_add_posts', array( &$this, 'posts_in_page' ) );
    2730        add_shortcode( 'ic_add_post', array( &$this, 'post_in_page' ) );
     31        add_action( 'admin_menu', array( &$this, 'plugin_page_init' ) );
    2832    }
    2933   
     
    3135        extract( shortcode_atts( array(
    3236            'category' => false,
     37            'cats' => false,
    3338            'post_type' => false,
    3439            'tax' => false,
     
    4348        self::set_args( $atts );
    4449        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';
    4568    }
    4669   
     
    5780    public function post_in_page( $atts ){
    5881        $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       
    6193        $page_posts = new WP_Query( $args );
     94        //fprint_r( $page_posts );
    6295        $output = '';
    6396        if( $page_posts->have_posts() ): while( $page_posts->have_posts()):
     
    73106        if($atts['ids'] ){
    74107            $post_ids = explode( ',', $atts['ids'] );
    75             $this->args['post_in'] = $post_ids;
     108            $this->args['post__in'] = $post_ids;
    76109            $this->args['posts_per_page'] = count( $post_ids );
    77110        }
     
    84117            $cats = explode( ',', $atts['category'] );
    85118            $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'];
    86122        }
    87123        if( $atts['tax'] ){
Note: See TracChangeset for help on using the changeset viewer.