下記のPHPのどこに
$popular = ob_get_clean();
$popular = str_replace('<ul class="wpp-list">', '<ul class="samecate">', $popular);
を入れたらulのclassを変えられますか?
ネットで調べてみましたが、もともとの書き方が違う例しか見つけられず、どこに記載していいか分かりません。分かる方、宜しくお願いします。
<?php if (function_exists('wpp_get_mostpopular')): ?>
<h3>よく読まれている<?php $cat = get_the_category(); $cat = $cat[0]; $catp = $cat->category_parent ; $catn = get_the_category_by_ID( $catp ); $catl = get_category_link( $catp ); ?><?php echo $catn; ?>情報</h3>
<?php
// オプションの設定
$args = array(
'limit' => 6,
'range' => 'weekly',
'order_by' => 'views',
'post_type' => 'post',
'thumbnail_width' => 80,
'thumbnail_height' => 80,
'title_length' => 40,
'post_html' => "<li>{thumb}{title}</li>"
);
global $_curcat;
if ($_curcat->term_id) {
if ($_curcat->category_parent != 0) {
$_curcat = get_top_category($_curcat->term_id);
}
$catids = get_categories('fields=ids&child_of=' . $_curcat->term_id);
$catids[] = $_curcat->term_id;
$args['cat'] = implode(',', $catids);
}
// 関数の実行
wpp_get_mostpopular($args);
?>
「wpp_start」に開始タグ「<ul class="samecate">」、「wpp_end」に終了タグ「</ul>」を追加指定してみてください。
・How to add classes to wpp_start and post_html tags (WordPress › Support » Plugins and Hacks > WordPress Popular Posts)※英語
https://wordpress.org/support/topic/how-to-add-classes-to-wpp_start-and-post_html-tags
※作者さん回答の2例目が配列によるオプション指定になっています。
・WordPress 調べたことメモ
http://qiita.com/GENYA/items/fb9a6fc2a7cf00b6192e
※ページ中ほど「・人気記事表示プラグイン「WordPress Popular Posts」を好きなHTMLで表示させよう」参照
指定可能なパラメータについては管理画面で確認できます。
・5. FAQ cabrerahector/wordpress-popular-posts Wiki · GitHub
---------------------------------------------------
Where can I find the list of parameters accepted by the wpp_get_mostpopular() template tag / [wpp] shortcode?
You can find it via wp-admin > Settings > WordPress Popular Posts > Parameters.
---------------------------------------------------
ご回答ありがとうございます。
下記のようにしてみたところ、画面が真っ白になってしまいました。
入れる場所がいけないのでしょうか・・・。
$args = array(
'limit' => 6,
'range' => 'weekly',
'order_by' => 'views',
'post_type' => 'post',
'thumbnail_width' => 80,
'thumbnail_height' => 80,
'title_length' => 40,
'wpp_start' => "<ul class="samecate">",
'wpp_end '=> "</ul>",
'post_html' => "<li>{thumb}{title}</li>"
);
すみません、白くなるのは直せました。
ただ、出力されるコードが変わりません。
全体のコードの私の書き方に間違いがあるのかもしれません。
<div class="kanren">
<?php if(post_is_in_category_slug(hoge) or post_is_in_category_slug(hoge1) or post_is_in_category_slug(hoge2)):?>
<?php
$html = "<li>{thumb} {title}</li>";
if (function_exists('wpp_get_mostpopular')) {
ob_start();
wpp_get_mostpopular('range=weekly&order_by=views&cat=13,10,12,11,9,112,18,19,16,15,14,17,101,20&limit=6&post_html="' . $html . '"&wpp_start="<ul>"&thumbnail_width=80&thumbnail_height=80&title_length=40');
$popular = ob_get_clean();
$popular = str_replace('<ul class="wpp-list">', '<ul class="samecate">', $popular);
echo '<h3>よく読まれている○○情報</h3>'. $popular;
}
?>
<?php else:?>
<?php if (function_exists('wpp_get_mostpopular')): ?>
<h3>よく読まれている<?php $cat = get_the_category(); $cat = $cat[0]; $catp = $cat->category_parent ; $catn = get_the_category_by_ID( $catp ); $catl = get_category_link( $catp ); ?><?php echo $catn; ?>情報</h3>
<?php
// オプションの設定
$args = array(
'limit' => 6,
'range' => 'weekly',
'order_by' => 'views',
'post_type' => 'post',
'thumbnail_width' => 80,
'thumbnail_height' => 80,
'title_length' => 40,
'wpp_start' => '<ul class="wpp-list">',
'wpp_end' => '</ul>',
'post_html' => "<li>{thumb}{title}</li>"
);
global $_curcat;
if ($_curcat->term_id) {
if ($_curcat->category_parent != 0) {
$_curcat = get_top_category($_curcat->term_id);
}
$catids = get_categories('fields=ids&child_of=' . $_curcat->term_id);
$catids[] = $_curcat->term_id;
$args['cat'] = implode(',', $catids);
}
// 関数の実行
wpp_get_mostpopular($args);
?>
<?php endif; ?>
<?php endif;?>
</div>
<div class="clear"></div>
大変失礼しました。
きちんと直りました。
'wpp_start' => '<ul class="wpp-list">',を'wpp_start' => '<ul class="samecate">',に変えなくてはならないのに、変え忘れてしまっていました。
アドバイス、本当にありがとうございました。
助かりました!!