指定したタグのついた投稿を1つのページに表示するには?
-
指定したタグのついた投稿記事を1つのページで表示したいと思っています。
例
A投稿のタイトル、記事 タグ:twitter
B投稿のタイトル、記事 タグ:twitter
Cというページ内に、
Aタイトル
A記事
Bタイトル
B記事
を表示する。特定のカテゴリを1つのページに表示するショートコードを見つけ、この改造を試みたのですが、うまくいきません。
function sc_post_list($atts, $content = null) {
global $post;$cur_cat = array_shift(get_the_category());
extract(shortcode_atts(array(
‘num’ => 5,
‘cat’ => $cur_cat->cat_ID,
‘format’ => ‘Y/m/d’
), $atts));$myposts = get_posts(‘numberposts=’ . $num . ‘&order=DESC&orderby=post_date&category=’ . $cat);
$ret = ”;foreach ($myposts as $post) {
setup_postdata($post);$content_txt = get_the_content();
// 改行を反映
$content_txt = preg_replace(“/\n/”,”
“,$content_txt);$ret .= $content_txt;
}
return $ret;
}
add_shortcode(‘post_list’, ‘sc_post_list’);ご教示をいただけないでしょうか?
- トピック「指定したタグのついた投稿を1つのページに表示するには?」には新たに返信することはできません。