Last active
August 29, 2015 13:55
-
-
Save snoise/8754420 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/ | |
*/ | |
$paka3obj = new Paka3_NewPost; | |
//呼び出し | |
add_filter('the_content',array($paka3obj,'paka3_newPosts')); | |
//クラス定義 | |
class Paka3_NewPost { | |
public $args; | |
//コンストラクタ | |
function __construct() { | |
$this->args = array( | |
'posts_per_page'=>3, | |
'orderby' =>'post_date', //投稿日 | |
'order' =>'DESC', | |
); | |
} | |
//新着リストメソッド | |
function paka3_newPosts($contentData){ | |
$posts =get_posts( $this->args ); | |
$list="<b>最新の記事</b><ol class='delStr_ul'>"; | |
foreach($posts as $post){ | |
//更新日のフォーマット変更 | |
$postDate = mysql2date('Y年m月d日', $post->post_date); | |
$list.="<li class='mylist_li'><a href='".get_permalink($post->ID)."' title='.$post->post_title.'>".$post->post_title."(更新日:".$postDate.")</a></li>"; | |
} | |
$list.="</ol>"; | |
return $list.$contentData; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment