PostViews テンプレートへの記述方法について
-
こちら(WP-PostViewsの順位表示を画像に)のブログ通りに行いたいのですが、「出力フォーマットの以下に」とあるのですが、その意味が分かりません。
下記の記述をテンプレートにどのように記述すれば良いか、どなたかお教え頂けないでしょうか、どうか宜しくお願い致します。
<li class="no%RANKING_NO%"> <a href="%POST_URL%" title="%POST_TITLE%">%POST_TITLE%</a> - %VIEW_COUNT% views</li>
1件の返信を表示中 - 1 - 1件目 (全1件中)
-
自己解決しましたので、投稿させて頂きます。
私がやりたかった事は、PostViewsを使って、人気記事にサムネイルを表示させるのと、順位毎にクラスを付加させることです。プラグインフォルダのwp-postview.phpを開き以下の記述がある箇所を探します。
(Postviewsのバージョンは1.66です。)foreach ($most_viewed as $post) { $post_views = intval($post->views); $post_title = get_the_title($post); if($chars > 0) { $post_title = snippet_text($post_title, $chars); } $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars); $temp = stripslashes($views_options['most_viewed_template']); $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp); $temp = str_replace("%POST_TITLE%", $post_title, $temp); $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp); $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp); $temp = str_replace("%POST_URL%", get_permalink($post), $temp); $temp = str_replace("%POST_DATE%", get_the_time(get_option('date_format'), $post), $temp); $temp = str_replace("%POST_TIME%", get_the_time(get_option('time_format'), $post), $temp); $output .= $temp; }上記と同じような記述が計6カ所あるのでそれら全てに、サムネイルを表示させる為の変数%THUMBNAIL%と順位毎にクラスを付与させる為の変数%RANKING_NO%を追加します。
$rankingNo = 1;//順位を計数する変数の定義 foreach ($most_viewed as $post) { $post_views = intval($post->views); $post_title = get_the_title($post); if($chars > 0) { $post_title = snippet_text($post_title, $chars); } $post_excerpt = views_post_excerpt($post->post_excerpt, $post->post_content, $post->post_password, $chars); $thumbnail = get_the_post_thumbnail($post->ID,"thumbnail",true);//サムネイルを表示 $temp = stripslashes($views_options['most_viewed_template']); $temp = str_replace("%VIEW_COUNT%", number_format_i18n($post_views), $temp); $temp = str_replace("%POST_TITLE%", $post_title, $temp); $temp = str_replace("%POST_EXCERPT%", $post_excerpt, $temp); $temp = str_replace("%POST_CONTENT%", $post->post_content, $temp); $temp = str_replace("%POST_URL%", get_permalink($post), $temp); $temp = str_replace("%THUMBNAIL%", $thumbnail, $temp);//サムネイルを表示 $temp = str_replace("%RANKING_NO%", $rankingNo, $temp);//変数への代入 $temp = str_replace("%POST_DATE%", get_the_time(get_option('date_format'), $post), $temp); $temp = str_replace("%POST_TIME%", get_the_time(get_option('time_format'), $post), $temp); $output .= $temp; $rankingNo++;//順位のカウントアップ }※上記の記述を他5カ所にも同じように記述します。
PostViewsの設定画面を開き、「Most Viewed Template:」右のテキスト入力欄に%THUMBNAIL%と%RANKING_NO%を追加記述します。
ちなみに僕は下記のように記述しています。
<div class="post"> <span class="no%RANKING_NO%"></span> <p class="post_image">%THUMBNAIL%</p> <h3><a href="%POST_URL%" title="%POST_TITLE%">%POST_TITLE%</a></h3> <p> %VIEW_COUNT% views</p> </div>順位毎にクラスを付与させる為の変数をclass=“no%RANKING_NO%”このようにクラス名の場所に記述。
続いてサムネイルを表示させる為の変数「%THUMBNAIL%」はそのまま記述しても大丈夫そうです。参考URL:WordPress(ワードプレス)でWP-PostViewsの順位表示を画像にしてみたい
WordPress人気記事にサムネイル表示させる方法とカスタマイズ
1件の返信を表示中 - 1 - 1件目 (全1件中)
トピック「PostViews テンプレートへの記述方法について」には新たに返信することはできません。