Created
July 9, 2014 02:06
-
-
Save hitsujixgit/96763ddc953af3b45362 to your computer and use it in GitHub Desktop.
ショートコードでslugを指定して、投稿記事を表示するプラグイン
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Include post | |
Plugin URI: http://wordpress.hitsuji.me | |
Description: ショートコードでslugを指定して、投稿記事を表示するプラグインです | |
Version: 1.0 | |
Author: Hitsuji | |
Author URI: http://hitsuji.me/about-me/ | |
*/ | |
function include_post_shortcode($atts) { | |
extract(shortcode_atts(array('slug' => ''), $atts)); | |
if ($atts['slug'] !== '' ) { | |
$args = array( | |
'name' => $atts['slug'], | |
'post_type' => 'post', | |
'post_status' => 'publish', | |
'numberposts' => 1, | |
); | |
$my_posts = get_posts($args); | |
if ($my_posts) { | |
$content = apply_filters( 'the_content', $my_posts[0]->post_content ); | |
$content = str_replace( ']]>', ']]>', $content ); | |
echo $content; | |
} | |
} | |
} | |
add_shortcode('include_post', 'include_post_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment