Last active
January 3, 2016 20:19
-
-
Save snoise/8514029 to your computer and use it in GitHub Desktop.
すべての記事に「最新の記事」のリンクを3件入れるwordpressプラグイン
This file contains 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: paka3 New Posts | |
Plugin URI: http://www.paka3.com/wpplugin | |
Description: すべての記事に「最新の記事」のリンクを3件入れる | |
Author: Shoji ENDO | |
Version: 0.1 | |
Author URI:http://www.paka3.com/ | |
*/ | |
function paka3_NewPosts($contentData) { | |
//条件定義 | |
$args = array( | |
'posts_per_page'=>3, | |
'orderby' =>'post_date', //投稿日 | |
'order' =>'DESC' | |
); | |
$posts =get_posts( $args ); | |
//リスト表示 | |
$list="<div class='newPosts'><b>最新の記事</b>"; | |
$list.="<ul class='mytaglist_ul'>"; | |
foreach($posts as $post){ | |
//更新日のフォーマット変更 | |
$postDate = mysql2date('Y年m月d日', $post->post_date); | |
$list.="<li><a href='". get_permalink($post->ID)."'>".$post->post_title."(更新日:".$postDate.")</a></li>"; | |
} | |
$list.="</ul></div>"; | |
return $contentData.$list; | |
} | |
add_filter('the_content','paka3_NewPosts'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment