Simplicityテーマで下記のような形で新着記事一覧を実装しています。
①特定のカテゴリーの新着記事だけにしたい場合はどうすればよいのか?
②個別の記事のカテゴリー(文字列)を取得するにはどうしたらよいか?(それぞれの記事の上にカテゴリーを表記したいため)
よろしくお願いします。
// function getNewPost2($opt) { extract(shortcode_atts(array( 'num' => '' ), $opt)); $num = (!empty($num)) ? $num : 5; $args = array( 'posts_per_page' => $num, 'orderby' => 'date', 'order' => 'DESC', 'post_type' => 'post', 'post_status' => 'publish' ); $posts_array = get_posts( $args ); $out = ""; $out .= "<h3 class='toph3'>新着投稿</h3><ul class='wpp-list topul'>"; foreach ($posts_array as $post) { $id = $post->ID; $title = $post->post_title; $post_date = get_the_time( get_theme_text_date_format(), $id); $post_modified = $post->post_modified; $link = get_the_permalink($id); $category = get_the_category($id); foreach ($category as $cat) { $cat_id = $cat->cat_ID; $cat_name = $cat->name; $cat_link = get_category_link($cat_id); $cats[] = "<a href='".$cat_link."' rel='category tag'>".$cat_name."</a>"; } $categorys = implode(", ",$cats); unset($cats); $out .= <<< EOD <li class="top-new-post topli"> <div class="post-date"> <span class="fa fa-clock-o fa-fw"></span> <span class="published">{$post_date}</span> </div> <a href="{$link}" title="{$title}" class="wpp-post-title" target="_self">{$title} </a> </li> EOD; } $out .= "</ul>"; //#list return $out; } add_shortcode('nplist-top', 'getNewPost2'); //
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/03/04 13:24
2017/03/04 13:35
2017/03/04 14:00