トップの画像リストに、記事抜粋を追加したい
-
当方、PHP初心者です。
自力で調べているのですが、中々どうしてピンとくる情報が無いので質問させて頂きます…(ご回答頂けると幸いです..twenty-elevenのindex.phpに以下のコードを書き込み、
画像ギャラリーの様な形で、記事を表示したいのです。現在は画像、タイトルとカテゴリーが表示されるのですが、
これに「記事の抜粋」を加えたいと思っています。※参考にさせて頂いた記事はこちらです
http://tenderfeel.xsrv.jp/wordpress/579/<?php get_header(); ?> <?php get_sidebar(); ?> <?php attachment_ancherlinks2(9); ?> <?php function attachment_ancherlinks2($num,$size="thumbnail"){ $args = "numberposts=".$num; $myposts = get_posts($args); print "<ul id=\"thumb-post-lists\">"; for($i=0;$i<$num;$i++){ if($i>= count($myposts) ) return; $attachments = get_children(array('post_parent' => $myposts[$i]->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order')); $url = $myposts[$i]->guid;//記事URL $title= $myposts[$i]->post_title;//タイトル $post_cats = wp_get_post_categories($myposts[$i]->ID);//カテゴリー $cat_num = count($post_cats); $x = 1; if(count($attachments)>= 1){ $attachment = array_shift($attachments); print " <li><a href="$url" title="$title">".wp_get_attachment_image($attachment->ID,$size)."</a>";//サムネイル出力 print "<a href="$url">$title</a>";//タイトル出力 foreach($post_cats as $cat){ $sep = $cat_num> $x ? ",":""; print "<span class=\"cat\">".get_cat_name($cat).$sep."</span>";//カテゴリ名 $x++; } print"</li> "; }else{ //画像が無い場合 print " <li><a href="$url">$title</a>";//NoImage print "<a href="$url">$title</a>";//タイトル出力 foreach($post_cats as $cat){ $sep = $cat_num> $x ? ",":""; print "<span class=\"cat\">".get_cat_name($cat).$sep."</span>";//カテゴリ名 $x++; } print"</li> "; } } print ""; } ?> <?php get_footer(); ?>
index.phpとstyle.css以外は弄っていません。
ご指導頂けると幸いです。よろしくお願い致します!
1件の返信を表示中 - 1 - 1件目 (全1件中)
1件の返信を表示中 - 1 - 1件目 (全1件中)
- トピック「トップの画像リストに、記事抜粋を追加したい」には新たに返信することはできません。