Skip to content

Instantly share code, notes, and snippets.

@snoise
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snoise/8712238 to your computer and use it in GitHub Desktop.
Save snoise/8712238 to your computer and use it in GitHub Desktop.
最新記事のタイトルのリンクを3件表示して、一部を削除してみるwordpressプラグイン
<?php
/*
Plugin Name: paka3 string delete 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_StrDelNewPosts($contentData){
/*例:
・タイトル1:【wordpress】
・タイトル2:【wordpress】
・タイトル3:【wordpress】
   ※この末尾の【wordpress】を表示のときに削除
・タイトル1
・タイトル2
・タイトル3
*/
$args = array(
'posts_per_page'=>3,
'orderby' =>'post_date', //投稿日
'order' =>'DESC',
);
$posts =get_posts( $args );
$list="<b>最新の記事</b><ol class='delStr_ul'>";
foreach($posts as $post){
if(preg_match('/:【.*/',$post->post_title, $regs)){
//更新日のフォーマット変更
$postDate = mysql2date('Y年m月d日', $post->post_date);
$post->post_title =str_replace( $regs[0],"", $post->post_title);
}
$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;
}
add_filter('the_content','paka3_StrDelNewPosts');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment