Version Description
- Added code to allow ignoring, or showing of sticky posts. By default, sticky posts are ignored, but can be re-enabled using the shortcode
[ic_add_posts ignore_sticky_posts='no']
.
Download this release
Release Info
Developer | sewmyheadon |
Plugin | Posts in Page |
Version | 1.2.1 |
Comparing to | |
See all releases |
Code changes from version 1.0.10 to 1.2.1
- lib/page_posts.php +163 -0
- posts_in_page.php +67 -134
- posts_loop_template.php +30 -26
- readme.txt +105 -23
lib/page_posts.php
ADDED
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Page Posts Class, main workhorse for the ic_add_posts shortcode.
|
4 |
+
*/
|
5 |
+
|
6 |
+
if ( !function_exists( 'add_action' ) )
|
7 |
+
wp_die( 'You are trying to access this file in a manner not allowed.', 'Direct Access Forbidden', array( 'response' => '403' ) );
|
8 |
+
|
9 |
+
class ICPagePosts {
|
10 |
+
|
11 |
+
protected $args = array(
|
12 |
+
'post_type' => 'post',
|
13 |
+
'post_status' => 'publish',
|
14 |
+
'orderby' => 'date',
|
15 |
+
'order' => 'DESC',
|
16 |
+
'template' => false
|
17 |
+
); // set defaults for wp_parse_args
|
18 |
+
|
19 |
+
public function __construct( $atts ) {
|
20 |
+
self::set_args( $atts );
|
21 |
+
}
|
22 |
+
|
23 |
+
/**
|
24 |
+
* Output's the posts
|
25 |
+
*
|
26 |
+
* @return string output of template file
|
27 |
+
*/
|
28 |
+
public function output_posts() {
|
29 |
+
if ( !$this->args ) return '';
|
30 |
+
$page_posts = apply_filters( 'posts_in_page_results', new WP_Query( $this->args ) ); // New WP_Query object
|
31 |
+
$output = '';
|
32 |
+
if ( $page_posts->have_posts( ) ):
|
33 |
+
while ( $page_posts->have_posts( ) ):
|
34 |
+
$output .= self::add_template_part( $page_posts );
|
35 |
+
endwhile;
|
36 |
+
$output .= '<div class="pip-nav">' . apply_filters( 'posts_in_page_paginate',
|
37 |
+
$this->paginate_links( $page_posts )
|
38 |
+
) . '</div>';
|
39 |
+
endif;
|
40 |
+
wp_reset_postdata( );
|
41 |
+
return $output;
|
42 |
+
}
|
43 |
+
|
44 |
+
protected function paginate_links( $posts ){
|
45 |
+
global $wp_query;
|
46 |
+
$page_url = home_url( '/' . $wp_query->post->post_name . '/' );
|
47 |
+
$page = isset( $_GET['page'] ) ? $_GET['page'] : 1;
|
48 |
+
$total_pages = $posts->max_num_pages;
|
49 |
+
$per_page = $posts->query_vars['posts_per_page'];
|
50 |
+
$curr_page = ( isset( $posts->query_vars['paged'] ) && $posts->query_vars['paged'] > 0 ) ? $posts->query_vars['paged'] : 1;
|
51 |
+
//echo '<pre>' . print_r( $posts, true ) . '</pre>';
|
52 |
+
$prev = ( $curr_page && $curr_page > 1 ) ? '<li><a href="'.$page_url.'?page='. ( $curr_page-1 ).'">Previous</a></li>' : '';
|
53 |
+
$next = ( $curr_page && $curr_page < $total_pages ) ? '<li><a href="'.$page_url.'?page='. ( $curr_page+1 ).'">Next</a></li>' : '';
|
54 |
+
return '<ul>' . $prev . $next . '</ul>';
|
55 |
+
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Build additional Arguments for the WP_Query object
|
59 |
+
*
|
60 |
+
* @param array $atts Attritubes for building the $args array.
|
61 |
+
*/
|
62 |
+
protected function set_args( $atts ) {
|
63 |
+
global $wp_query;
|
64 |
+
$this->args['posts_per_page'] = get_option( 'posts_per_page' );
|
65 |
+
// parse the arguments using the defaults
|
66 |
+
$this->args = wp_parse_args( $atts, $this->args );
|
67 |
+
|
68 |
+
// multiple post types are indicated, pass as an array
|
69 |
+
if( preg_match( '`,`', $this->args['post_type'] ) ){
|
70 |
+
$post_types = explode( ',', $this->args['post_type'] );
|
71 |
+
$this->args['post_type'] = $post_types;
|
72 |
+
}
|
73 |
+
|
74 |
+
// Show specific posts by ID
|
75 |
+
if ( isset( $atts['ids'] ) ) {
|
76 |
+
$post_ids = explode( ',', $atts['ids'] );
|
77 |
+
$this->args['post__in'] = $post_ids;
|
78 |
+
$this->args['posts_per_page'] = count( $post_ids );
|
79 |
+
}
|
80 |
+
|
81 |
+
// Use a specified template
|
82 |
+
if ( isset( $atts['template'] ) )
|
83 |
+
$this->args['template'] = $atts['template'];
|
84 |
+
|
85 |
+
// get posts in a certain category by name (slug)
|
86 |
+
if ( isset( $atts['category'] ) ) {
|
87 |
+
$this->args['category_name'] = $atts['category'];
|
88 |
+
} elseif ( isset( $atts['cats'] ) ) { // get posts in a certain category by id
|
89 |
+
$this->args['cat'] = $atts['cats'];
|
90 |
+
}
|
91 |
+
|
92 |
+
// Do a tex query, tax and term a required.
|
93 |
+
if( isset( $atts['tax'] ) ) {
|
94 |
+
if( isset( $atts['term'] ) ){
|
95 |
+
$terms = explode( ',', $atts['term'] );
|
96 |
+
$this->args['tax_query'] = array(
|
97 |
+
array( 'taxonomy' => $atts['tax'], 'field' => 'slug', 'terms' => ( count( $terms ) > 1 ) ? $terms : $atts['term'] )
|
98 |
+
);
|
99 |
+
}
|
100 |
+
}
|
101 |
+
|
102 |
+
// get posts with a certain tag
|
103 |
+
if ( isset( $atts['tag'] ) ) {
|
104 |
+
$tags = explode( ',', $atts['tag'] );
|
105 |
+
$this->args['tag'] = ( count( $tags ) > 1 ) ? $tags : $atts['tag'];
|
106 |
+
}
|
107 |
+
|
108 |
+
// show number of posts (default is 10, showposts or posts_per_page are both valid, only one is needed)
|
109 |
+
if ( isset( $atts['showposts'] ) )
|
110 |
+
$this->args[ 'posts_per_page' ] = $atts['showposts'];
|
111 |
+
|
112 |
+
// handle pagination (for code, template pagination is in the template)
|
113 |
+
if ( isset( $wp_query->query_vars['page'] ) && $wp_query->query_vars['page'] > 1 ) {
|
114 |
+
$this->args['paged'] = $wp_query->query_vars['page'];
|
115 |
+
}
|
116 |
+
|
117 |
+
if ( ! isset( $this->args['ignore_sticky_posts'] ) ) {
|
118 |
+
$this->args['post__not_in'] = get_option( 'sticky_posts' );
|
119 |
+
}
|
120 |
+
|
121 |
+
if ( ! isset( $this->args['ignore_sticky_posts'] ) ) {
|
122 |
+
$this->args['post__not_in'] = get_option( 'sticky_posts' );
|
123 |
+
}
|
124 |
+
|
125 |
+
$this->args = apply_filters( 'posts_in_page_args', $this->args );
|
126 |
+
}
|
127 |
+
|
128 |
+
/**
|
129 |
+
* Tests if a theme has a theme template file that exists
|
130 |
+
*
|
131 |
+
* @return true if template exists, false otherwise.
|
132 |
+
*/
|
133 |
+
protected function has_theme_template( ) {
|
134 |
+
$template_file = ( $this->args['template'] )
|
135 |
+
? get_stylesheet_directory( ) . '/' . $this->args['template'] // use specified template file
|
136 |
+
: get_stylesheet_directory( ) . '/posts_loop_template.php'; // use default template file
|
137 |
+
|
138 |
+
return ( file_exists( $template_file ) ) ? $template_file : false;
|
139 |
+
}
|
140 |
+
|
141 |
+
/**
|
142 |
+
* Retrieves the post loop template and returns the output
|
143 |
+
*
|
144 |
+
* @return string results of the output
|
145 |
+
*/
|
146 |
+
protected function add_template_part( $ic_posts, $singles=false ) {
|
147 |
+
if ( $singles ) {
|
148 |
+
setup_postdata( $ic_posts );
|
149 |
+
} else {
|
150 |
+
$ic_posts->the_post( );
|
151 |
+
}
|
152 |
+
$output = '';
|
153 |
+
ob_start( );
|
154 |
+
$output .= apply_filters( 'posts_in_page_pre_loop', '' );
|
155 |
+
require ( $file_path = self::has_theme_template( ) )
|
156 |
+
? $file_path // use template file in theme
|
157 |
+
: POSTSPAGE_DIR . '/posts_loop_template.php'; // use default plugin template file
|
158 |
+
$output .= ob_get_contents( );
|
159 |
+
$output .= apply_filters( 'posts_in_page_post_loop', '' );
|
160 |
+
return ob_get_clean( );
|
161 |
+
}
|
162 |
+
|
163 |
+
}
|
posts_in_page.php
CHANGED
@@ -6,12 +6,12 @@
|
|
6 |
* Description: Easily add one or more posts to any page using simple shortcodes. Supports categories, tags, custom post types, custom taxonomies, and more.
|
7 |
* Author: IvyCat Web Services
|
8 |
* Author URI: http://www.ivycat.com
|
9 |
-
* version: 1.
|
10 |
* License: GNU General Public License v2.0
|
11 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
13 |
------------------------------------------------------------------------
|
14 |
-
IvyCat
|
15 |
|
16 |
This program is free software; you can redistribute it and/or modify
|
17 |
it under the terms of the GNU General Public License as published by
|
@@ -29,159 +29,92 @@
|
|
29 |
|
30 |
*/
|
31 |
|
32 |
-
|
33 |
-
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
public function __construct(){
|
40 |
add_shortcode( 'ic_add_posts', array( &$this, 'posts_in_page' ) );
|
41 |
add_shortcode( 'ic_add_post', array( &$this, 'post_in_page' ) );
|
42 |
add_action( 'admin_menu', array( &$this, 'plugin_page_init' ) );
|
43 |
add_filter( 'plugin_action_links_'. plugin_basename( __FILE__ ), array( &$this, 'plugin_action_links' ), 10, 4 );
|
44 |
}
|
45 |
|
|
|
|
|
|
|
46 |
public function plugin_action_links( $actions, $plugin_file, $plugin_data, $context ) {
|
47 |
if ( is_plugin_active( $plugin_file ) )
|
48 |
$actions[] = '<a href="' . admin_url('options-general.php?page=posts_in_page') . '">' . __( ' Help', 'posts_in_page' ) . '</a>';
|
49 |
-
return $actions;
|
50 |
}
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
'tag' => false,
|
61 |
-
'template' => false,
|
62 |
-
'ids' => false,
|
63 |
-
'orderby' => false,
|
64 |
-
'order' => false
|
65 |
-
), $atts ) );
|
66 |
-
self::set_args( $atts );
|
67 |
-
return self::output_posts();
|
68 |
}
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
$hooks[] = add_options_page( __( 'Posts In Page' ), __( 'Posts In Page' ), 'read', 'posts_in_page',
|
74 |
-
array( $this, 'plugin_page') );
|
75 |
-
|
76 |
-
|
|
|
77 |
}
|
78 |
}
|
79 |
|
80 |
-
|
|
|
|
|
|
|
81 |
wp_enqueue_style( 'postpagestyle', POSTPAGE_URL. '/assets/post-page_styles.css' );
|
82 |
wp_enqueue_script( 'postpagescript', POSTPAGE_URL. '/assets/post-page_scripts.js' );
|
83 |
}
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
86 |
require_once 'assets/posts_in_page_help_view.php';
|
87 |
}
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
public function post_in_page( $atts ){
|
100 |
-
$args = array( 'post_type' => ( $atts['post_type'] ) ? $atts['post_type'] : 'post' );
|
101 |
-
if( $atts['id'] ) {
|
102 |
-
$ids = explode( ',', $atts['id'] );
|
103 |
-
if( count( $ids ) > 1 ):
|
104 |
-
$args['post__in'] = $ids;
|
105 |
-
$args['posts_per_page'] = count( $ids );
|
106 |
-
else:
|
107 |
-
$args['p'] = $atts['id'];
|
108 |
-
$args['posts_per_page'] = 1;
|
109 |
-
endif;
|
110 |
-
}
|
111 |
-
|
112 |
-
$page_posts = new WP_Query( $args );
|
113 |
-
//fprint_r( $page_posts );
|
114 |
-
$output = '';
|
115 |
-
if( $page_posts->have_posts() ): while( $page_posts->have_posts()):
|
116 |
-
$output .= self::add_template_part( $page_posts );
|
117 |
-
endwhile; endif;
|
118 |
-
wp_reset_postdata();
|
119 |
-
return $output;
|
120 |
-
}
|
121 |
-
|
122 |
-
protected function set_args( $atts ){
|
123 |
-
global $wp_query;
|
124 |
-
$this->args = array( 'post_type' => ( $atts['post_type'] ) ? $atts['post_type'] : 'post' );
|
125 |
-
$this->args['post_status'] = 'publish';
|
126 |
-
if($atts['ids'] ){
|
127 |
-
$post_ids = explode( ',', $atts['ids'] );
|
128 |
-
$this->args['post__in'] = $post_ids;
|
129 |
-
$this->args['posts_per_page'] = count( $post_ids );
|
130 |
-
}
|
131 |
-
if( $atts['orderby'] ){
|
132 |
-
$this->args['orderby'] = $atts['orderby'];
|
133 |
-
}
|
134 |
-
if( $atts['order'] )
|
135 |
-
$this->args['order'] = $atts['order'];
|
136 |
-
|
137 |
-
if( $atts['template'] ) $this->args['template'] = $atts['template'];
|
138 |
-
if( $atts['category'] ){
|
139 |
-
$cats = explode( ',', $atts['category'] );
|
140 |
-
$this->args['category_name'] = ( count( $cats ) > 1 ) ? $cats : $atts['category'];
|
141 |
-
}elseif( $atts['cats'] ){
|
142 |
-
$cats = explode( ',', $atts['cats'] );
|
143 |
-
$this->args['category_name'] = ( count( $cats ) > 1 ) ? $cats : $atts['cats'];
|
144 |
-
}
|
145 |
-
if( $atts['tax'] ){
|
146 |
-
if( $atts['term'] ){
|
147 |
-
$terms = explode( ',', $atts['term'] );
|
148 |
-
$this->args['tax_query'] = array(
|
149 |
-
array( 'taxonomy' => $atts['tax'], 'field' => 'slug', 'terms' => ( count( $terms ) > 1 ) ? $terms : $atts['term'] )
|
150 |
-
);
|
151 |
-
}
|
152 |
-
}
|
153 |
-
if( $atts['tag'] ){
|
154 |
-
$tags = explode( ',', $atts['category'] );
|
155 |
-
$this->args['tag'] = ( count( $tags ) > 1 ) ? $tags : $atts['tag'];
|
156 |
-
}
|
157 |
-
if( !$this->args['posts_per_page'] ) $this->args[ 'posts_per_page' ] = $atts['showposts'];
|
158 |
-
if( $wp_query->query_vars['page'] > 1 ){
|
159 |
-
$this->args['paged'] = $wp_query->query_vars['page'];
|
160 |
-
}
|
161 |
-
}
|
162 |
-
|
163 |
-
protected function has_theme_template(){
|
164 |
-
$template_file = ( $this->args['template'] ) ? self::current_theme_path() . '/' . $this->args['template'] : self::current_theme_path() . '/posts_loop_template.php';
|
165 |
-
|
166 |
-
return ( file_exists( $template_file ) ) ? $template_file : false;
|
167 |
-
}
|
168 |
-
|
169 |
-
protected function add_template_part( $ic_posts, $singles=false ){
|
170 |
-
if( $singles ){
|
171 |
-
setup_postdata( $ic_posts );
|
172 |
-
}else{
|
173 |
-
$ic_posts->the_post();
|
174 |
-
}
|
175 |
-
ob_start();
|
176 |
-
require ( $file_path = self::has_theme_template() ) ? str_replace( site_url(), '', $file_path ) : 'posts_loop_template.php';
|
177 |
-
$output .= ob_get_contents();
|
178 |
-
return ob_get_clean();
|
179 |
-
}
|
180 |
-
|
181 |
-
protected function current_theme_path(){
|
182 |
-
$theme_data = explode( '/', get_bloginfo( 'stylesheet_directory' ) );
|
183 |
-
$theme_path = get_theme_root();
|
184 |
-
return $theme_path . '/' . $theme_data[ count( $theme_data ) -1 ];
|
185 |
-
}
|
186 |
-
|
187 |
-
} new AddPostsToPage();
|
6 |
* Description: Easily add one or more posts to any page using simple shortcodes. Supports categories, tags, custom post types, custom taxonomies, and more.
|
7 |
* Author: IvyCat Web Services
|
8 |
* Author URI: http://www.ivycat.com
|
9 |
+
* version: 1.2.1
|
10 |
* License: GNU General Public License v2.0
|
11 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
12 |
|
13 |
------------------------------------------------------------------------
|
14 |
+
IvyCat Posts in Page, Copyright 2012 IvyCat, Inc. (admins@ivycat.com)
|
15 |
|
16 |
This program is free software; you can redistribute it and/or modify
|
17 |
it under the terms of the GNU General Public License as published by
|
29 |
|
30 |
*/
|
31 |
|
32 |
+
if ( !function_exists( 'add_action' ) )
|
33 |
+
wp_die( 'You are trying to access this file in a manner not allowed.', 'Direct Access Forbidden', array( 'response' => '403' ) );
|
34 |
|
35 |
+
if ( ! defined( 'POSTSPAGE_DIR' ) )
|
36 |
+
define( 'POSTSPAGE_DIR', plugin_dir_path( __FILE__ ) );
|
37 |
+
|
38 |
+
if ( ! defined( 'POSTPAGE_URL' ) )
|
39 |
+
define( 'POSTPAGE_URL', plugin_dir_url( __FILE__ ) );
|
40 |
+
|
41 |
+
require_once 'lib/page_posts.php';
|
42 |
+
|
43 |
+
class ICAddPostsToPage {
|
44 |
|
45 |
+
public function __construct( ) {
|
46 |
add_shortcode( 'ic_add_posts', array( &$this, 'posts_in_page' ) );
|
47 |
add_shortcode( 'ic_add_post', array( &$this, 'post_in_page' ) );
|
48 |
add_action( 'admin_menu', array( &$this, 'plugin_page_init' ) );
|
49 |
add_filter( 'plugin_action_links_'. plugin_basename( __FILE__ ), array( &$this, 'plugin_action_links' ), 10, 4 );
|
50 |
}
|
51 |
|
52 |
+
/**
|
53 |
+
* Add settings link on plugins page.
|
54 |
+
*/
|
55 |
public function plugin_action_links( $actions, $plugin_file, $plugin_data, $context ) {
|
56 |
if ( is_plugin_active( $plugin_file ) )
|
57 |
$actions[] = '<a href="' . admin_url('options-general.php?page=posts_in_page') . '">' . __( ' Help', 'posts_in_page' ) . '</a>';
|
58 |
+
return apply_filters( 'post_in_page_actions', $actions );
|
59 |
}
|
60 |
|
61 |
+
/**
|
62 |
+
* Main Shortcode
|
63 |
+
*
|
64 |
+
* @param array $atts An array of shortcode parameters. None required
|
65 |
+
*/
|
66 |
+
public function posts_in_page( $atts ) {
|
67 |
+
$posts = new ICPagePosts( $atts );
|
68 |
+
return $posts->output_posts( );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Deprecated Shortcode (routing to posts in page function now )
|
73 |
+
*
|
74 |
+
* @todo Remove this depreciated function.
|
75 |
+
*/
|
76 |
+
public function post_in_page( $atts ) {
|
77 |
+
return self::posts_in_page( $atts );
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Init Plugin, add menu page and setup hooks to load assets on the plugin options page
|
82 |
+
*/
|
83 |
+
public function plugin_page_init() {
|
84 |
+
if ( ! current_user_can( 'administrator' ) )
|
85 |
+
return;
|
86 |
+
|
87 |
+
$hooks = array( );
|
88 |
$hooks[] = add_options_page( __( 'Posts In Page' ), __( 'Posts In Page' ), 'read', 'posts_in_page',
|
89 |
+
array( $this, 'plugin_page' ) );
|
90 |
+
|
91 |
+
foreach ( $hooks as $hook ) {
|
92 |
+
add_action( "admin_print_styles-{$hook}", array( $this, 'load_assets' ) );
|
93 |
}
|
94 |
}
|
95 |
|
96 |
+
/**
|
97 |
+
* Enqueue Plugin Assets (Scripts and Styles)
|
98 |
+
*/
|
99 |
+
public function load_assets( ) {
|
100 |
wp_enqueue_style( 'postpagestyle', POSTPAGE_URL. '/assets/post-page_styles.css' );
|
101 |
wp_enqueue_script( 'postpagescript', POSTPAGE_URL. '/assets/post-page_scripts.js' );
|
102 |
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Plugin Setting page - includes view for the page
|
106 |
+
*/
|
107 |
+
public function plugin_page( ) {
|
108 |
require_once 'assets/posts_in_page_help_view.php';
|
109 |
}
|
110 |
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Instantiate the Plugin - called using the plugins_loaded action hook.
|
115 |
+
*/
|
116 |
+
function init_ic_posts_in_page( ) {
|
117 |
+
new ICAddPostsToPage( );
|
118 |
+
}
|
119 |
+
|
120 |
+
add_action( 'plugins_loaded', 'init_ic_posts_in_page' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
posts_loop_template.php
CHANGED
@@ -1,31 +1,35 @@
|
|
1 |
<!-- Note: if you make changes to this file, move it to your current theme's
|
2 |
directory so this file won't be overwritten when the plugin is upgraded. -->
|
3 |
|
4 |
-
<!--
|
5 |
-
<
|
|
|
|
|
6 |
|
7 |
-
<!-- This is the output of the excerpt -->
|
8 |
-
<div class="entry-summary">
|
9 |
-
|
10 |
-
</div>
|
11 |
|
12 |
-
<!-- This is the output of the meta information -->
|
13 |
-
<div class="entry-utility">
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
</div>
|
|
|
|
1 |
<!-- Note: if you make changes to this file, move it to your current theme's
|
2 |
directory so this file won't be overwritten when the plugin is upgraded. -->
|
3 |
|
4 |
+
<!-- Start of Post Wrap -->
|
5 |
+
<div class="post hentry ivycat-post">
|
6 |
+
<!-- This is the output of the post title -->
|
7 |
+
<h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
|
8 |
|
9 |
+
<!-- This is the output of the excerpt -->
|
10 |
+
<div class="entry-summary">
|
11 |
+
<?php the_excerpt(); ?>
|
12 |
+
</div>
|
13 |
|
14 |
+
<!-- This is the output of the meta information -->
|
15 |
+
<div class="entry-utility">
|
16 |
+
<?php if ( count( get_the_category() ) ) : ?>
|
17 |
+
<span class="cat-links">
|
18 |
+
<?php printf( __( '<span class="%1$s">Posted in</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-cat-links', get_the_category_list( ', ' ) ); ?>
|
19 |
+
</span>
|
20 |
+
<span class="meta-sep">|</span>
|
21 |
+
<?php endif; ?>
|
22 |
+
<?php
|
23 |
+
$tags_list = get_the_tag_list( '', ', ' );
|
24 |
+
if ( $tags_list ):
|
25 |
+
?>
|
26 |
+
<span class="tag-links">
|
27 |
+
<?php printf( __( '<span class="%1$s">Tagged</span> %2$s', 'twentyten' ), 'entry-utility-prep entry-utility-prep-tag-links', $tags_list ); ?>
|
28 |
+
</span>
|
29 |
+
<span class="meta-sep">|</span>
|
30 |
+
<?php endif; ?>
|
31 |
+
<span class="comments-link"><?php comments_popup_link( __( 'Leave a comment', 'twentyten' ), __( '1 Comment', 'twentyten' ), __( '% Comments', 'twentyten' ) ); ?></span>
|
32 |
+
<?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
|
33 |
+
</div>
|
34 |
+
</div>
|
35 |
+
<!-- // End of Post Wrap -->
|
readme.txt
CHANGED
@@ -4,51 +4,92 @@ Donate link: http://www.ivycat.com/contribute/
|
|
4 |
Tags: shortcode, pages, posts, custom post types
|
5 |
Requires at least: 3.0
|
6 |
Tested up to: 3.4.1
|
7 |
-
Stable tag: 1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
11 |
-
Easily add
|
12 |
|
13 |
-
==Description==
|
14 |
|
15 |
-
Easily add one or more posts to any page using simple shortcodes.
|
16 |
|
17 |
-
|
18 |
|
19 |
-
|
|
|
|
|
20 |
|
21 |
This is a minimal plugin, function over form. If you would like to extend it, or would like us to extend it in later versions, please post feature suggestions in the plugin's [support forum](http://wordpress.org/support/plugin/posts-in-page) or [contact us](http://www.ivycat.com/contact/).
|
22 |
|
|
|
|
|
23 |
== Installation ==
|
24 |
|
25 |
You can install from within WordPress using the Plugin/Add New feature, or if you wish to manually install:
|
26 |
|
27 |
1. Download the plugin.
|
28 |
-
1. Upload the entire `
|
29 |
-
1. Activate the plugin in your WordPress
|
30 |
-
1. Start embedding
|
|
|
|
|
31 |
|
32 |
-
|
33 |
|
34 |
-
|
|
|
|
|
|
|
35 |
|
36 |
* `[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.
|
37 |
-
* `[ic_add_posts ids='1,2,3']` - show one or many posts by specifying the post ID(s) (
|
38 |
-
* `[ic_add_posts post_type='post_type']` - show posts from a custom post type by specifying the post type slug ( must give post type if not a standard post )
|
39 |
* `[ic_add_posts showposts='5']` - limit number of posts (or override default setting)
|
40 |
-
* `[ic_add_posts orderby='title' order='ASC']` - orderby title - supports all WP orderby variables. Order is optional, WP default
|
41 |
* `[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.)
|
42 |
* `[ic_add_posts tag='tag-slug']` - Show posts using a specific tag. Like categories, it uses slugs, and can accommodate multiple tags separate by commas. tag-1,tag-2, etc (no spaces.)
|
43 |
-
* `[ic_add_posts post_type='post-type']` - Show posts that are a specific post type (only one post type right now)
|
44 |
* `[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
|
45 |
* `[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.
|
|
|
46 |
|
47 |
-
Or any combination above.
|
48 |
|
49 |
-
|
50 |
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
== Frequently Asked Questions ==
|
54 |
|
@@ -60,14 +101,47 @@ This plugin goes well with our [Simple Page Specific Sidebars](http://wordpress.
|
|
60 |
|
61 |
= How do I change the output template =
|
62 |
|
63 |
-
Simply copy the posts_loop_template.php to your theme directory and make changes as necessary.
|
64 |
|
65 |
You can even rename it - but make sure to indicate that in the shortcode using the `template='template_name.php'`.
|
66 |
|
67 |
You can even use different templates for each shortcode if you like.
|
68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
== Changelog ==
|
70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
= 1.0.10 =
|
72 |
* Added check for published/private posts.
|
73 |
|
@@ -92,6 +166,18 @@ You can even use different templates for each shortcode if you like.
|
|
92 |
|
93 |
== Upgrade Notice ==
|
94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
= 1.0.10 =
|
96 |
* Added feature - non-critical update.
|
97 |
|
@@ -113,8 +199,4 @@ You can even use different templates for each shortcode if you like.
|
|
113 |
= 1.0.3 =
|
114 |
* Added single post or specific post capabilities. Important feature.
|
115 |
|
116 |
-
== Road Map ==
|
117 |
-
|
118 |
-
1. Suggest a feature...
|
119 |
-
|
120 |
|
4 |
Tags: shortcode, pages, posts, custom post types
|
5 |
Requires at least: 3.0
|
6 |
Tested up to: 3.4.1
|
7 |
+
Stable tag: 1.2.1
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
11 |
+
Easily add one or more posts to any page using simple shortcodes.
|
12 |
|
13 |
+
== Description ==
|
14 |
|
15 |
+
Easily add one or more posts to any page using simple shortcodes.
|
16 |
|
17 |
+
Supports categories, tags, custom post types, custom taxonomies, and more.
|
18 |
|
19 |
+
You can get all of the same functionality provided by this plugin by modifying your theme's template files; this plugin just makes it easy for anyone to _pull_ posts into other areas of the site without having to modify theme files.
|
20 |
+
|
21 |
+
Plugin is depending upon your theme's styling; version 1.x of this plugin _does not_ contain native styles.
|
22 |
|
23 |
This is a minimal plugin, function over form. If you would like to extend it, or would like us to extend it in later versions, please post feature suggestions in the plugin's [support forum](http://wordpress.org/support/plugin/posts-in-page) or [contact us](http://www.ivycat.com/contact/).
|
24 |
|
25 |
+
Give us feedback and contribute to this plugin on its [GitHub page](https://github.com/ivycat/Posts-in-Page)
|
26 |
+
|
27 |
== Installation ==
|
28 |
|
29 |
You can install from within WordPress using the Plugin/Add New feature, or if you wish to manually install:
|
30 |
|
31 |
1. Download the plugin.
|
32 |
+
1. Upload the entire `posts-in-page` directory to your plugins folder
|
33 |
+
1. Activate the plugin from the plugin page in your WordPress Dashboard
|
34 |
+
1. Start embedding posts in whatever pages you like using shortcodes.
|
35 |
+
|
36 |
+
### Shortcode Usage
|
37 |
|
38 |
+
To 'pull' posts into a page, you can either:
|
39 |
|
40 |
+
1. place a shortcode in the editor window of the page you're editing, or
|
41 |
+
1. modify a theme template file using the shortcode in a PHP function.
|
42 |
+
|
43 |
+
#### Using Shortcodes in the WordPress editor
|
44 |
|
45 |
* `[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.
|
46 |
+
* `[ic_add_posts ids='1,2,3']` - show one or many posts by specifying the post ID(s) ( specify all post types )
|
47 |
+
* `[ic_add_posts post_type='post_type']` - show posts from a custom post type by specifying the post type slug ( must give post type if not a standard post ) add multiple post types by separating with commas (ex. `post_type='post_type1,post_type2'`)
|
48 |
* `[ic_add_posts showposts='5']` - limit number of posts (or override default setting)
|
49 |
+
* `[ic_add_posts orderby='title' order='ASC']` - orderby title - supports all WP orderby variables. Order is optional, WP default is 'DESC'.
|
50 |
* `[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.)
|
51 |
* `[ic_add_posts tag='tag-slug']` - Show posts using a specific tag. Like categories, it uses slugs, and can accommodate multiple tags separate by commas. tag-1,tag-2, etc (no spaces.)
|
|
|
52 |
* `[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
|
53 |
* `[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.
|
54 |
+
* `[ic_add_posts ignore_sticky_posts='no']` - Show sticky posts too (they're ignored by default).
|
55 |
|
56 |
+
Or any combination of the above.
|
57 |
|
58 |
+
#### Shortcode Examples
|
59 |
|
60 |
+
Not sure how to use the shortcodes above to get what you want? Here are a few examples to get you started:
|
61 |
+
|
62 |
+
** Example 1 **
|
63 |
+
|
64 |
+
Let's say you want to pull a specific post called _"What I love about coffee"_, which has a post ID of 34, somewhere on your About Us page. Your shortcode should look like this:
|
65 |
+
|
66 |
+
`[ic_add_posts ids='34']`
|
67 |
+
|
68 |
+
** Example 2 **
|
69 |
+
|
70 |
+
Alright, now lets say that you want to pull in all posts from two categories into your WordPress page. One category is _WordPress Rocks_ and the other is _WordPress Rolls_. Plus, you'd like to display them three per page, rather than the default number of posts. Depending on your category slugs, your shortcode should probably look like this:
|
71 |
+
|
72 |
+
`[ic_add_posts category='wordpress-rocks,wordpress-rolls' showposts='3']`
|
73 |
+
|
74 |
+
** Example 3 **
|
75 |
+
|
76 |
+
Now, you're ambitious and want to try something complex. Let's say you've got a page called _Plugins Are Awesome_ and, in it, you want to pull in posts that match the following criteria:
|
77 |
+
|
78 |
+
* posts from a custom post type called _Testimonials_,
|
79 |
+
* posts that are in the _Testimonial Type_ custom taxonomy using the term _Customer_
|
80 |
+
* you want to display six testimonials per page,
|
81 |
+
* you'd like them displayed in ascending order
|
82 |
+
* finally, you've created a custom template to use in presenting these posts and named it `my-posts-in-page-template.php`
|
83 |
+
|
84 |
+
Your shortcode might look like this:
|
85 |
+
|
86 |
+
`[ic_add_posts showposts='6' post_type='testimonials' tax='testimonial-type' term='customer' order='ASC' template='my-posts-in-page-template.php']`
|
87 |
+
|
88 |
+
#### Using Shortcodes within a PHP function
|
89 |
+
|
90 |
+
If you'd like to use this plugin to pull posts directly into your theme's template files, you can drop the following WordPress function in your template files, replacing the `[shortcode]` part with your, custom shortcode.
|
91 |
+
|
92 |
+
`<?php echo do_shortcode("[shortcode]"); ?>`
|
93 |
|
94 |
== Frequently Asked Questions ==
|
95 |
|
101 |
|
102 |
= How do I change the output template =
|
103 |
|
104 |
+
Simply copy the `posts_loop_template.php` to your theme directory and make changes as necessary.
|
105 |
|
106 |
You can even rename it - but make sure to indicate that in the shortcode using the `template='template_name.php'`.
|
107 |
|
108 |
You can even use different templates for each shortcode if you like.
|
109 |
|
110 |
+
= Does it work with custom post types? =
|
111 |
+
|
112 |
+
Absolutely.
|
113 |
+
|
114 |
+
= How about with custom taxonomies?
|
115 |
+
|
116 |
+
You bet.
|
117 |
+
|
118 |
+
= Will it make me coffee?
|
119 |
+
|
120 |
+
Not likely, but let us know if it does; then we'll know we have something special.
|
121 |
+
|
122 |
+
== Screenshots ==
|
123 |
+
|
124 |
+
1. Embed a shortcode into a page and it will automatically pull in the post(s) you need.
|
125 |
+
2. Embed shortcodes directly in your template using `do_shortcode`.
|
126 |
+
|
127 |
== Changelog ==
|
128 |
|
129 |
+
= 1.2.1 =
|
130 |
+
* Added code to allow ignoring, or showing of sticky posts. By default, sticky posts are ignored, but can be re-enabled using the shortcode `[ic_add_posts ignore_sticky_posts='no']`.
|
131 |
+
|
132 |
+
= 1.2.0 =
|
133 |
+
* Code maintenance to better comply with standards
|
134 |
+
* Added post pagination
|
135 |
+
* Plugin now honors default post reading settings under Settings/Reading in the WordPress Dashboard.
|
136 |
+
* Improved and simplified documentation.
|
137 |
+
* Added filters & hooks (documentation coming)
|
138 |
+
|
139 |
+
= 1.1.1 =
|
140 |
+
* Code maintenance, fix for category bug, also added ability for multiple post types per shortcode.
|
141 |
+
|
142 |
+
= 1.1.0 =
|
143 |
+
* Code maintenance, squash non-critical debug notices.
|
144 |
+
|
145 |
= 1.0.10 =
|
146 |
* Added check for published/private posts.
|
147 |
|
166 |
|
167 |
== Upgrade Notice ==
|
168 |
|
169 |
+
= 1.2.1 =
|
170 |
+
* Small feature update, not critical.
|
171 |
+
|
172 |
+
= 1.2.0 =
|
173 |
+
* Important feature update - please upgrade.
|
174 |
+
|
175 |
+
= 1.1.1 =
|
176 |
+
* Small bug fix; please upgrade.
|
177 |
+
|
178 |
+
= 1.1.0 =
|
179 |
+
* Code maintenance & housekeeping - non-critical update.
|
180 |
+
|
181 |
= 1.0.10 =
|
182 |
* Added feature - non-critical update.
|
183 |
|
199 |
= 1.0.3 =
|
200 |
* Added single post or specific post capabilities. Important feature.
|
201 |
|
|
|
|
|
|
|
|
|
202 |
|