Changeset 554359
- Timestamp:
- 06/07/2012 02:50:31 PM (14 years ago)
- Location:
- posts-in-page/trunk
- Files:
-
- 2 edited
-
posts_in_page.php (modified) (6 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
posts-in-page/trunk/posts_in_page.php
r542073 r554359 4 4 Author: dgilfoy, ivycat 5 5 Description: Add Posts in page 6 Version: 1.0. 16 Version: 1.0.2 7 7 8 Shortcode usage:8 Shortcode usage: 9 9 [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) 11 13 [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.) 12 14 [ic_add_posts post_type='post-type'] - Show posts that are a specific post type (only one post type right now) … … 22 24 public function __construct(){ 23 25 add_shortcode( 'ic_add_posts', array( &$this, 'posts_in_page' ) ); 26 add_shortcode( 'ic_add_post', array( &$this, 'post_in_page' ) ); 24 27 } 25 28 … … 32 35 'showposts' => 10, 33 36 'tag' => false, 34 'template' => false 37 'template' => false, 38 'ids' => false 35 39 ), $atts ) ); 36 40 self::set_args( $atts ); … … 48 52 } 49 53 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 50 67 protected function set_args( $atts ){ 51 68 global $wp_query; 52 69 $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 } 53 75 if( $atts['template'] ) $this->args['template'] = $atts['template']; 54 76 if( $atts['category'] ){ … … 68 90 $this->args['tag'] = ( count( $tags ) > 1 ) ? $tags : $atts['tag']; 69 91 } 70 $this->args[ 'posts_per_page' ] = $atts['showposts'];92 if( !$this->args['posts_per_page'] ) $this->args[ 'posts_per_page' ] = $atts['showposts']; 71 93 if( $wp_query->query_vars['page'] > 1 ){ 72 94 $this->args['paged'] = $wp_query->query_vars['page']; … … 80 102 } 81 103 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(); 88 114 } 89 115 -
posts-in-page/trunk/readme.txt
r542068 r554359 4 4 Requires at least: 3.0 5 5 Tested up to: 3.1 6 Stable tag: 1.0. 16 Stable tag: 1.0.2 7 7 8 8 ==Short Description == … … 30 30 31 31 Shortcode 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. 39 41 40 42 == Screenshots == … … 46 48 A: 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 47 49 a more granular control of sidebars on specific categories/post-types etc. 50 Q: How do I change the output template 51 A: 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. 48 52 49 53 == Changelog == 50 54 51 55 1. 2012-06-07: Added single post or specific post capabilities. 52 56 53 57 == Upgrade Notice ==
Note: See TracChangeset
for help on using the changeset viewer.