Plugin Directory

Changeset 554359


Ignore:
Timestamp:
06/07/2012 02:50:31 PM (14 years ago)
Author:
dgilfoy
Message:

Added single post or mulitple specific posts - also updated some of the documentation.

Location:
posts-in-page/trunk
Files:
2 edited

Legend:

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

    r542073 r554359  
    44    Author: dgilfoy, ivycat
    55    Description: Add Posts in page
    6     Version: 1.0.1
     6    Version: 1.0.2
    77   
    8     Shortcode usage:
     8   Shortcode usage:
    99    [ic_add_posts]  - Add all posts to a page (limit to what number posts in wordpress is set to), essentially adds blog "page" to page.
    10     [ic_add_posts showposts=5] - limit number of posts (or override default setting)
     10    [ic_add_posts post_type='post_type' ids='1,2,3'] - show posts with certain IDs (currently only one post type per category)
     11    [ic_add_post id='1'] - show a single post with the given ID ( must give post type if not post )
     12    [ic_add_posts showposts='5'] - limit number of posts (or override default setting)
    1113    [ic_add_posts category='category-slug']  - Show posts within a specific category.  Uses slugs, can have multiple but separate by commas. category-1,category2, etc (no spaces.)
    1214    [ic_add_posts post_type='post-type'] - Show posts that are a specific post type (only one post type right now)
     
    2224    public function __construct(){
    2325        add_shortcode( 'ic_add_posts', array( &$this, 'posts_in_page' ) );
     26        add_shortcode( 'ic_add_post', array( &$this, 'post_in_page' ) );
    2427    }
    2528   
     
    3235            'showposts' => 10,
    3336            'tag' => false,
    34             'template' => false
     37            'template' => false,
     38            'ids' => false
    3539        ), $atts ) );
    3640        self::set_args( $atts );
     
    4852    }
    4953   
     54    public function post_in_page( $atts ){
     55        $args = array( 'post_type' => (  $atts['post_type'] ) ? $atts['post_type'] : 'post' );
     56        if( $atts['id'] ) $args['post_in'] = array( $atts['id'] );
     57        $args['posts_per_page'] = 1;
     58        $page_posts = new WP_Query( $args );
     59        $output = '';
     60        if( $page_posts->have_posts() ): while( $page_posts->have_posts()):
     61        $output .= self::add_template_part( $page_posts );
     62        endwhile; endif;
     63        wp_reset_postdata();
     64        return $output;
     65    }
     66   
    5067    protected function set_args( $atts ){
    5168        global $wp_query;
    5269        $this->args = array( 'post_type' => (  $atts['post_type'] ) ? $atts['post_type'] : 'post' );
     70        if($atts['ids'] ){
     71            $post_ids = explode( ',', $atts['ids'] );
     72            $this->args['post_in'] = $post_ids;
     73            $this->args['posts_per_page'] = count( $post_ids );
     74        }
    5375        if( $atts['template'] ) $this->args['template'] = $atts['template'];
    5476        if( $atts['category'] ){
     
    6890            $this->args['tag'] = ( count( $tags ) > 1 ) ? $tags : $atts['tag'];
    6991        }
    70         $this->args[ 'posts_per_page' ] = $atts['showposts'];
     92        if( !$this->args['posts_per_page'] ) $this->args[ 'posts_per_page' ] = $atts['showposts'];
    7193        if( $wp_query->query_vars['page'] > 1 ){
    7294            $this->args['paged'] = $wp_query->query_vars['page'];
     
    80102    }
    81103   
    82    protected function add_template_part( $ic_posts ){
    83       $ic_posts->the_post();
    84       ob_start();
    85       require ( $file_path = self::has_theme_template() ) ? str_replace( site_url(), '', $file_path ) : 'posts_loop_template.php';
    86       $output .= ob_get_contents();
    87       return ob_get_clean();
     104   protected function add_template_part( $ic_posts, $singles=false ){
     105        if( $singles ){
     106            setup_postdata( $ic_posts );
     107        }else{
     108            $ic_posts->the_post();
     109        }
     110        ob_start();
     111        require ( $file_path = self::has_theme_template() ) ? str_replace( site_url(), '', $file_path ) : 'posts_loop_template.php';
     112        $output .= ob_get_contents();
     113        return ob_get_clean();
    88114   }
    89115   
  • posts-in-page/trunk/readme.txt

    r542068 r554359  
    44Requires at least: 3.0
    55Tested up to: 3.1
    6 Stable tag: 1.0.1
     6Stable tag: 1.0.2
    77
    88==Short Description ==
     
    3030
    3131Shortcode usage:
    32 * [ic_add_posts]  - Add all posts to a page (limit to what number posts in wordpress is set to), essentially adds blog "page" to page.
    33 * [ic_add_posts showposts=5] - limit number of posts (or override default setting)
    34 * [ic_add_posts category='category-slug']  - Show posts within a specific category.  Uses slugs, can have multiple but separate by commas. category-1,category2, etc (no spaces.)
    35 * [ic_add_posts post_type='post-type'] - Show posts that are a specific post type (only one post type right now)
    36 * [ic_add_posts tax='taxonomy' term='term'] - limit posts to those that exist in a taxonomy and have a specific term.  Both are required for either one to work
    37 * [ic_add_posts template='template-in-theme-dir.php'] - In case you want to style your markup, add meta data, etc.  Each shortcode can reference a different template.  These templates must exist in the theme directory.
    38 * Or any combination
     32    * [ic_add_posts]  - Add all posts to a page (limit to what number posts in wordpress is set to), essentially adds blog "page" to page.
     33    * [ic_add_posts post_type='post_type' ids='1,2,3'] - show posts with certain IDs (currently only one post type per category)
     34    * [ic_add_post id='1'] - show a single post with the given ID ( must give post type if not post )
     35    * [ic_add_posts showposts='5'] - limit number of posts (or override default setting)
     36    * [ic_add_posts category='category-slug']  - Show posts within a specific category.  Uses slugs, can have multiple but separate by commas.   category-1,category2, etc (no spaces.)
     37    * [ic_add_posts post_type='post-type'] - Show posts that are a specific post type (only one post type right now)
     38    * [ic_add_posts tax='taxonomy' term='term'] - limit posts to those that exist in a taxonomy and have a specific term.  Both are required for either one to work
     39    * [ic_add_posts template='template-in-theme-dir.php'] - In case you want to style your markup, add meta data, etc.  Each shortcode can reference a different template.  These templates must exist in the theme directory.
     40    Or any combination above.
    3941
    4042== Screenshots ==
     
    4648A: Well, some of our clients wanted to output some posts in a specific page without fiddling with templates.  This plugin goes well page specific sidebars and giving you
    4749a more granular control of sidebars on specific categories/post-types etc.
     50Q: How do I change the output template
     51A: Simply copy the posts_loop_template.php to your theme directory and make changes as necessary. You can even rename it - but make sure to indicate that in the shortcode using the template='template_name.php'.  You can even use multiple layouts for each shortcode if you like.
    4852
    4953== Changelog ==
    5054
    51 
     551. 2012-06-07: Added single post or specific post capabilities.
    5256
    5357== Upgrade Notice ==
Note: See TracChangeset for help on using the changeset viewer.