• ベストアンサー
※ ChatGPTを利用し、要約された質問です(原文:WordPressの質問(q10054200)の続)

WordPressの質問(q10054200):コメントにハートマークをつけていいねボタンをカウントする方法

dell_OKの回答

  • dell_OK
  • ベストアンサー率13% (743/5657)
回答No.6

コメント欄 その66】 ・コメントが取得できないのかvar_dump()で調べてみたところ$postには値が確認できたのですが、$commentは空でした。 どのタイミングでダンプされたのかわかりませんが、 変数名は正しく表記してください。 「$comments」ですか。 「$comment」ですと、 foreach ($comments as $comment) {}の中でダンプする必要があります。 取得の確認でしたら、取得直後でダンプしてみてください。 ---- if (3 === $tn) { $args['post_id'] = $post_red->ID; /* 赤のID */ $comments_red = get_comments($args); /* 赤のコメント */ var_dump($comments_red); $args['post_id'] = $post_blue->ID; /* 青のID */ $comments_blue = get_comments($args); /* 青のコメント */ var_dump($comments_blue); $args['post_id'] = $post_green->ID; /* 緑のID */ $comments_green = get_comments($args); /* 緑のコメント */ var_dump($comments_green); } elseif (2 === $tn) { $args['post_id'] = $post_white->ID; /* 白のID */ $comments_white = get_comments($args); /* 白のコメント */ var_dump($comments_white); $args['post_id'] = $post_black->ID; /* 黒のID */ $comments_black = get_comments($args); /* 黒のコメント */ var_dump($comments_black); } else { $args['post_id'] = $post_single->ID; $comments_single = get_comments($args); var_dump($comments_single); } ---- ・数日前に($post, $comments)の$commentsを追加した記憶があるのですがもしかしたらこれが原因となっているかもしれません。 display_single_comment($post, $comments)の($post, $comments)でしたら、 以前からありますので、追加されたのはここではないと思います。 ・$commentsは両方でNULLとなっており、$comments as $commentで値を空のまま渡しているようです。 $commentsがnullであればempty()がtrueで、 「コメントなし」の表示処理になるため、 $comments as $commentの処理は実行されません。 ・$commentをダイレクトに渡すことは可能でしょうか? ダイレクトの意味がわかりません。

php_learn
質問者

補足

foreach ($comments as $comment) {}の中でダンプする必要があります。 $commentsがnullであればempty()がtrueで、 「コメントなし」の表示処理になるため、 $comments as $commentの処理は実行されません。 A.アドバイスありがとうございます。foreach内でダンプするんですね… どこでも確認できるのかと思っておりました。 勘違いでした、申し訳ありません。

関連するQ&A

  • WordPressの質問(q10165331)の続

    URLを連番にすべきかuuidにすべきか迷っているのですが、どちらが良いと思われますでしょうか? 一連番号のIDを避けるべきなのであればメジャーなサイトはすべてランダム文字列になっているはずではないかという意見とURLが予測しやすいと攻撃しやすいという意見があるようです。 IDを付ける際にBase58を使う、N 進数の文字列を使うなどuuid意外にも色んな方法があるようで、どうすべきか分かりません、アドバイスお願い致します。 $url = home_url('質問表示画面?'.$row->ID); ※idをautoincrementしない方が良い理由 https://zenn.dev/praha/articles/3c84e3818891c3 ※ユーザIDを連番にしてURLに使っても問題ない https://teratail.com/questions/364664 https://detail.chiebukuro.yahoo.co.jp/qa/question_detail/q11270700181 ※短縮URLの付け方 https://sousaku-memo.net/php-system/71 https://co.bsnws.net/article/256 ※htmlspecialcharsでIDをエスケープ http://lovee7.blog.fc2.com/blog-entry-34.html 質問一覧表示(single-que_list.php) 回答可能なページ(single-complete.php) <?php /* Template Name: que_list 固定ページ: 質問一覧画面 */ get_header(); $sql = 'SELECT * FROM sortable'; $query = $wpdb->prepare($sql); $rows = $wpdb->get_results($query); $upload_dir = wp_upload_dir(); foreach ($rows as $row) { $url = home_url('質問表示画面?'.$row->ID); $pattern = $upload_dir['basedir'].'/attach/'.$row->ID.'_0.*'; $files = glob($pattern); if (empty($files)) { $view = '<img src="ダミー画像パス">'; } else { $info = pathinfo($files[0]); $attach_url = $upload_dir['baseurl'].'/attach/'.$info['basename']; $ext = $info['extension']; switch ($ext) { case 'jpeg': case 'png': $view = '<img style="height: 50px;" src="'.$attach_url.'">'; break; case 'mp4': $view = '<video style="height: 50px;" src="'.$attach_url.'">'; break; case 'pdf': $view = '<iframe style="height: 50px;" src="'.$attach_url.'"></iframe>'; break; default: $view = ''; break; } } echo '<div><a href="'.$url.'">'.$row->unique_id; echo '<div>'.$row->namae.'</div>'; echo '<div>'.$view.'</div>'; echo '<div>'.mb_strimwidth($row->message, 0, 38, '・・・').'</div>'; echo '</a></div>'; } ?>

    • ベストアンサー
    • PHP
  • WordPress アクセス時一度だけ500エラー

    レンタルサーバーにWordPressを2つ(別ディレクトリに)インストールして利用しているのですが、そのうちの片方だけが表題のような状態になっており困っています。 具体的には、どうやらその日最初のアクセスのみ500エラーが返され、それ以降は何事もなく表示されているようなのです。(現在準備中のため、アクセスするのが設置者である私だけです) SQLiteプラグインを利用しているのでその辺りが怪しいとは思うのですが、まったく同じ構成のもう一方ではこの現象が発生しておらず、またエラーが発生する方も、この現象以外はまったく問題なく、記事の投稿などが行えている状態です。 サーバーのエラーログを頼りに調べてみたのですが、インストール時の問題が多く、同じような状況に出会うことができませんでした。 皆様のお知恵をお貸しいただければと思います。 サーバー:inetd エラーログ: WordPress database error <div style="clear:both">&nbsp;</div><div class="queries" style="clear:both; margin_bottom:2px; border: red dotted thin;">Queries made or created this session were<br/>\r \t<ol>\r \t\t<li>Raw query:\tSELECT COUNT(NULLIF(`meta_value` LIKE '%administrator%', FALSE)), COUNT(NULLIF(`meta_value` LIKE '%editor%', FALSE)), COUNT(NULLIF(`meta_value` LIKE '%author%', FALSE)), COUNT(NULLIF(`meta_value` LIKE '%contributor%', FALSE)), COUNT(NULLIF(`meta_value` LIKE '%subscriber%', FALSE)), COUNT(*) FROM wp_usermeta WHERE meta_key = 'wp_capabilities'</li>\r \t\t<li>Rewritten: SELECT COUNT(NULLIF(meta_value LIKE '%administrator%', FALSE)), COUNT(NULLIF(meta_value LIKE '%editor%', FALSE)), COUNT(NULLIF(meta_value LIKE '%author%', FALSE)), COUNT(NULLIF(meta_value LIKE '%contributor%', FALSE)), COUNT(NULLIF(meta_value LIKE '%subscriber%', FALSE)), COUNT(*) FROM wp_usermeta WHERE meta_key = 'wp_capabilities'</li>\r \t\t<li>With Placeholders: SELECT COUNT(NULLIF(meta_value LIKE ? , FALSE)), COUNT(NULLIF(meta_value LIKE ? , FALSE)), COUNT(NULLIF(meta_value LIKE ? , FALSE)), COUNT(NULLIF(meta_value LIKE ? , FALSE)), COUNT(NULLIF(meta_value LIKE ? , FALSE)), COUNT(*) FROM wp_usermeta WHERE meta_key = ? </li>\r \t\t<li>Prepare:\tSELECT COUNT(NULLIF(meta_value LIKE ? , FALSE)), COUNT(NULLIF(meta_value LIKE ? , FALSE)), COUNT(NULLIF(meta_value LIKE ? , FALSE)), COUNT(NULLIF(meta_value LIKE ? , FALSE)), COUNT(NULLIF(meta_value LIKE ? , FALSE)), COUNT(*) FROM wp_usermeta WHERE meta_key = ? </li>\r \t</ol>\r </div><div style="clear:both; margin_bottom:2px; border: red dotted thin;" class="errorMessage" style="border-bottom:dotted blue thin;">Error occurred at line 431 in Function prepareQuery. <br/> Error message was: Problem preparing the PDO SQL Statement. Error was no such column: FALSE </div><pre>#0 PDO_Engine->getErrorMessage() called at [/example.com/wp-content/pdo/db.php:170] #1 pdo_db->query(SELECT COUNT(NULLIF(`meta_value` LIKE '%administrator%', FALSE)), COUNT(NULLIF(`meta_value` LIKE '%editor%', FALSE)), COUNT(NULLIF(`meta_value` LIKE '%author%', FALSE)), COUNT(NULLIF(`meta_value` LIKE '%contributor%', FALSE)), COUNT(NULLIF(`meta_value` LIKE '%subscriber%', FALSE)), COUNT(*) FROM wp_usermeta WHERE meta_key = 'wp_capabilities') called at [/example.com/wp-includes/wp-db.php:1296] #2 wpdb->get_row(SELECT COUNT(NULLIF(`meta_value` LIKE '%administrator%', FALSE)), COUNT(NULLIF(`meta_value` LIKE '%editor%', FALSE)), COUNT(NULLIF(`meta_value` LIKE '%author%', FALSE)), COUNT(NULLIF(`meta_value` LIKE '%contributor%', FALSE)), COUNT(NULLIF(`meta_value` LIKE '%subscriber%', FALSE)), COUNT(*) FROM wp_usermeta WHERE meta_key = 'wp_capabilities', ARRAY_N) called at [/example.com/wp-includes/user.php:857] #3 count_users() called at [/example.com/wp-includes/update.php:54] #4 wp_version_check() #5 call_user_func_array(wp_version_check, Array ()) called at [/example.com/wp-includes/plugin.php:486] #6 do_action_ref_array(wp_version_check, Array ()) called at [/example.com/wp-cron.php:55] </pre> for query SELECT COUNT(NULLIF(`meta_value` LIKE '%administrator%', FALSE)), COUNT(NULLIF(`meta_value` LIKE '%editor%', FALSE)), COUNT(NULLIF(`meta_value` LIKE '%author%', FALSE)), COUNT(NULLIF(`meta_value` LIKE '%contributor%', FALSE)), COUNT(NULLIF(`meta_value` LIKE '%subscriber%', FALSE)), COUNT(*) FROM wp_usermeta WHERE meta_key = 'wp_capabilities' made by do_action_ref_array, call_user_func_array, wp_version_check, count_users, pdo_db->query, pdo_db->print_error Premature end of script headers: php5.cgi

    • 締切済み
    • PHP
  • WordPressの質問(q10155839)の続

    var_dump($row);で確認したところ登録結果画面と質問表示画面でNULLが表示されております。 コードをたどったところ質問表示画面の$sql = 'SELECT * FROM sortable WHERE URL=%s';で取得に失敗しているのではないかと考えたのですが、エラー原因は分かりますでしょうか? ※データベースにURLは格納されております。 https://imgur.com/5RmSq2Y.jpg ※該当コード $url = substr($_SERVER['REQUEST_URI'], -36); $sql = 'SELECT * FROM sortable WHERE URL=%s'; $query = $wpdb->prepare($sql, $url); $rows = $wpdb->get_results($query); var_dump($row); if (empty($rows)) { echo '質問がみつかりません'; exit; } ________________________________________________________________________ Q.テーブルにカラムを追加して保存するようにしてみてください。 A.アドバイスありがとうございます、下記コードでIPアドレスは保存できるようですが、入力画面、確認画面、表示画面どのタイミングで追加すべきでしょうか? $ip_address = $_SERVER["REMOTE_ADDR"]; //文字列形式から数値 に、数値から文字列形式に変換 $ip_long = ip2long($ip_address); -- ipアドレスのテーブル CREATE TABLE tbl_ips ( `ip` INT(10) NOT NULL ); $sql = "INSERT INTO tbl_ips ( ip ) VALUES ( INET_ATON( $ip ) );" Q.こんな感じになります。 メッセージの一部、については以前やったことがあると思いますので、$row->messageから取得するようにしてみてください。 A.アドバイスありがとうございます、メッセージの一部を取得というコードを考えてみました。1点質問があるのですが、<a href="'.$url.'"></a>を名前、画像、メッセージ全体に1つだけかけたい場合どのようなコードにすればよいのでしょうか? ---- <?php /* Template Name: 質問一覧画面 */ get_header(); $sql = 'SELECT * FROM sortable'; $query = $wpdb->prepare($sql); $rows = $wpdb->get_results($query); $upload_dir = wp_upload_dir(); foreach ($rows as $row) { $url = home_url('質問表示画面?'.$row->URL); $pattern = $upload_dir['basedir'].'/attach/'.$row->ID.'_0.*'; $files = glob($pattern); if (empty($files)) { $view = '<img src="ダミー画像パス">'; } else { $info = pathinfo($files[0]); $attach_url = $upload_dir['baseurl'].'/attach/'.$info['basename']; $ext = $info['extension']; switch ($ext) { case 'jpeg': case 'png': $view = '<img style="height: 50px;" src="'.$attach_url.'">'; break; case 'mp4': $view = '<video style="height: 50px;" src="'.$attach_url.'">'; break; case 'pdf': $view = '<iframe style="height: 50px;" src="'.$attach_url.'"></iframe>'; break; default: $view = ''; break; } } echo '<div><a href="'.$url.'">'.$row->namae.'</a></div>';    echo '<div>'.$view.'</div>'; echo '<div>'.mb_strimwidth($row->message, 0, 38, "・・・").'</div>'; } ---- 昨日教えて頂いた質問掲示板 登録結果画面のタイトルから飛べるページをリンク先として考えておりました。 http://www.irasuto.cfbx.jp/%e9%9b%91%e8%ab%87%e6%8e%b2%e7%a4%ba%e6%9d%bf%e3%80%80%e7%99%bb%e9%8c%b2%e7%b5%90%e6%9e%9c%e7%94%bb%e9%9d%a2/

    • ベストアンサー
    • PHP
  • phpコードを解説して欲しいです。$str 多く困

    $str = '<h3 id="trackbacks">Trackback</h3>'; $str .= '<ol class="trackback-list" id="custom-trackback">'; $i = 0; foreach ( $comments as $comment ) { if ( get_comment_type() != 'comment' ) { $str .= '<li class="clearfix" id="comment-' . get_comment_ID() . '">'; $str .= '<div class="trackback-author">'; $str .= '<p class="comment-author-name">'; $comment_author_url = $comment->comment_author_url; $comment_author = $comment->comment_author; if ( $comment_author_url ) { $str .= '<a href="' . esc_url( $comment_author_url ) . '" target="_blank" title="' . esc_attr( $comment_author ) . '">'; $str .= esc_html( $comment_author ); $str .= '</a>'; } else { $str .= esc_html( $comment_author ); } $str .= '</p>'; $str .= '<p class="comment-meta">' . '<a href="' . esc_url( get_comment_link( $comment->comment_ID ) ) . '">' . get_comment_date() .'<span>'. get_comment_time() . '</span><a class="edit" href="' . get_edit_comment_link() . '">(編集)</a></span></p>'; $str .='</div>'; $str .= '<div class="trackback-body">'; if ( $comment->comment_approved == '0' ) { $str .= '<p class="attention"><em>あなたのトラックバックは承認待ちです。</em></p>'; } $str .= '<p>' . esc_html( get_comment_text() ) . '</p>'; $str .= '</div>'; $str .= '</li>'; $i++; } } $str .= '</ol>'; if ( $i > 0 ) { echo $str;

    • 締切済み
    • PHP
  • wordpressで

    wordpressを使ってブログを作っています。しかしcssを読み込んでくれません。 index.phpの内容は <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" /> <title><?php bloginfo('name'); ?><?php wp_title(': '); ?></title> <meta name="generator" content="WordPress <?php bloginfo('version'); ?>" /> <!-- leave this for stats please --> <link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?>(RSS 2.0)" href="<?php bloginfo('rss2_url'); ?>" /> <link rel="alternate" type="application/atom+xml" title="<?php bloginfo('name'); ?>(Atom)" href="<?php bloginfo('atom_url'); ?>" /> <link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_url'); ?>" /> </head> <body> <div id="rap"> <div id="header"> <div id="headerimg"> <h1><a href="<?php echo get_settings('home'); ?>/"><img src="img/title.gif" alt="芦澤治療院はやさしいマッサージで施術いたします。" /></a></h1> </div> <div id="headernavi"> <div id="navi"> <ul> <li><a href="#"><img src="img/link.gif" alt="" border="0" /></a></li> <li><a href="#"><img src="img/sitemap.gif" alt="" border="0" /></a></li> <li><a href="#"><img src="img/inquary.gif" alt="" border="0" /></a></li> </ul></div> <div id="size"> <img src="img/sizeword.gif" alt="" /> <a href="#"><img src="img/sizesmall.gif" alt="" border="0" /></a> <a href="#"><img src="img/sizemiddle.gif" alt="" border="0" /></a> <a href="#"><img src="img/sizebig.gif" alt="" border="0" /></a></div> </div> </div> <div id="navcontainer"> <ul> <li class="news"><a href="#">ニュース</a></li> <li class="cut"><img src="img/linecut.gif" alt="" /></li> <li class="work"><a href="#">施術の案内</a></li> <li class="cut"><img src="img/linecut.gif" alt="" /></li> <li class="stuff"><a href="#">スタッフ</a></li> <li class="cut"><img src="img/linecut.gif" alt="" /></li> <li class="qa"><a href="#">よくある質問</a></li> <li class="cut"><img src="img/linecut.gif" alt="" /></li> <li class="inq"><a href="#">お問い合わせ</a></li> </ul> </div> <!-- end header --> <div id="content"> <div id="main"> <?php if(have_posts()):while(have_posts()):the_post();?> <div class="post"> <h2><?php the_title();?></h2> <?php the_content();?> <p class="postmetadate"> <?php the_time('Y年m月d日 H:i')?>|<?php comments_popup_link ('コメント(1)','コメント(2)','コメント(%)');?> </p> </div> <?php comments_template();?> <?php endwhile;endif;?> </div> </div> </div> </body> </html> です。 ディレクトリ構造はindex.htmlとstyle.cssは同じフォルダにあります。

    • 締切済み
    • PHP
  • cake php paginateについて

    コントローラー内でpaginateの件数を扱いたいのですがどうやればいいのでしょうか? 色々調べてみましたがView側で件数を取得する <?php echo $this->Paginator->counter(array( 'format' => '<div class="count">%count%件見つかりました!</div>'));?> しか見つかりませんでした。よろしくお願いします。

    • ベストアンサー
    • PHP
  • as句に付与された'を"に変換する方法

    素人で申し訳ないのですが知恵を貸してください。 質問追記欄に記載のようなSQL文があったとして、as句に付与されている「'」のみを「"」に変換するプログラムを作りたいと思っています。言語はC言語です。 【SQL例文】 SELECT date as '日付',count as 'カウント' FROM view3; ↓変換後 SELECT date as "日付",count as "カウント" FROM view3; よろしくお願いします。

  • FC2ブログ・スタイルシート内で文字の大きさ変更の仕方を教えて下さい。

    FC2ブログ・スタイルシート内で文字の大きさ変更の仕方を教えて下さい。(font sizeと言う文字が無いので私は困った。) 以下はブログのソースコード <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <html lang="ja"> <head> <meta http-equiv="content-type" content="text/html; charset=euc-jp"> <meta http-equiv="content-style-type" content="text/css"> <meta http-equiv="content-script-type" content="text/javascript"> <link href="<%css_link>" type="text/css" rel="stylesheet"> <link rel="alternate" type="application/rss+xml" title="RSS" href="<%url>?xml"> <title><%blog_name> <%sub_title></title> <link href="<%css_link>" rel="stylesheet" type="text/css" /> </head> <body> <!-- headBlock --> <div id="headBlock"> <h1 class="h1"><a href="<%url>"><%blog_name></a></h1> <div id="headIntroduction"><%introduction></div> </div> <div class="login"><a href="./?admin">管理者ページ</a>&nbsp;<a name="page_top"></a></div> <!-- /headBlock --> <!-- EntryBlock --> <div id="EntryBlock"> <!--index_area--> <!--TopPage Only--> <div class="top_entry-index"> <div class="top_entry-body"> ■<strong>フリースペース</strong><br /> <br /> </div> </div> <!--/index_area--> <!--topentry--> <div class="mainEntryBlock"> <div class="mainEntryBase"> <div class="mainEntryTitle"><h2><a href="<%topentry_link>"><%topentry_title></a></h2></div> <div class="mainEntryBody"><%topentry_body></div> <div class="mainEntryMore"> <!--more_link--> ≫<a href="<%topentry_link>#more">[<%topentry_title>]の続きを読む</a> <!--/more_link--> <!--more--> <a name="more" id="more"></a><%topentry_more> <!--/more--> </div> </div> <div class="mainEntryDate"><a href="<%topentry_link>"><%topentry_year>/<%topentry_month>/<%topentry_day>(<%topentry_wayoubi>) </a> | <a href="<%topentry_category_link>"><%topentry_category></a> | <!--allow_tb--> <a href="<%topentry_link>#trackback">トラックバック:<%topentry_tb_num></a> | <!--/allow_tb--> <!--deny_tb--> <!--/deny_tb--> <!--allow_comment--> <a href="<%topentry_link>#comment">コメント:<%topentry_comment_num></a> | <!--/allow_comment--> <a href="#page_top" title="ページトップへ">PageTop↑</a> <!--deny_comment--> <!--/deny_comment--> </div> <!--<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:dc="http://purl.org/dc/elements/1.1/"> <rdf:Description rdf:about="<%topentry_link>" trackback:ping="<%url>tb.php/<%topentry_tb_no>" dc:title="<%topentry_title>" dc:identifier="<%topentry_link>" dc:subject="<%topentry_category>" dc:description="<%topentry_discription>" dc:creator="<%author_name>" dc:date="<%topentry_year>-<%topentry_month>-<%topentry_day>T<%topentry_hour>:<%topentry_minute>:<%topentry_second>+09:00" /> </rdf:RDF> --> </div> <!--/topentry--> <!--エントリーここまで--> <!--コメント--> <!--comment_area--> <div class="pageLink"> <!--preventry--> ≪<a href="<%preventry_url>"><%preventry_title></a> <!--/preventry--> | <a href="<%url>">ホーム</a> | <!--nextentry--> <a href="<%nextentry_url>"><%nextentry_title></a>≫ <!--/nextentry--> </div> <div class="mainEntryBlock"> <div class="mainEntryTitle"><a name="comment" id="comment"></a>コメント</div> <div class="mainEntryBase"> <div class="mainCommentBold">この記事へのコメント</div> <!--comment--> 割愛部分あり

  • WPのカテゴリのビュー数を表示させたい

    WordPress でプラグインを使用しないで記事のビュー数を表示させるコードは結構あったので見つけることができました。 -------------- //PV数をカスタムフィールドに保存 function wpb_set_post_views($postID) { $count_key = 'wpb_post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ $count = 0; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); }else{ $count++; update_post_meta($postID, $count_key, $count); } } remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); //投稿が閲覧されるたびにカスタムフィールドの値が更新 function wpb_track_post_views ($post_id) { if ( !is_single() ) return; if ( empty ( $post_id) ) { global $post; $post_id = $post->ID; } wpb_set_post_views($post_id); } add_action( 'wp_head', 'wpb_track_post_views'); //PV数取得 function wpb_get_post_views($postID){ $count_key = 'wpb_post_views_count'; $count = get_post_meta($postID, $count_key, true); if($count==''){ delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); return "0 View"; } return $count.' Views'; } --------------------- これを記事ではなくて、カテゴリでランキングを付けたい場合はどうすればいいのかがわかりません。 1)どのカテゴリが一番人気があるか、記事でなくカテゴリでランキングをつけたいです。 2)また、ビュー数を毎月調べたいので、1か月毎に初期化(0からカウント)するにはどうすればいいのかも教えて欲しいです。 3)もし、プラグインでカテゴリのビュー数を表示できるのがあったら、該当のプラグインを教えてほしいです。 よろしくお願い致します。

    • ベストアンサー
    • PHP
  • Wordpressのコメント欄受付・表示について。

    WordPress 2.8.6で構築 現在全てのブログでコメント受付が非表示になっていますが、その中の1つのカテゴリのブログだけでコメント欄を表示させるのが目的です。 phpの知識が追い付かずネットでも解決方法が見つけられず、以下のcomments.phpを修正してカテゴリの設定を変更するイメージでしたが理解が追い付きません。 どなたかお詳しい方いらっしゃいますでしょうか? <?php // Do not delete these lines if (isset($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME'])) die ('Please do not load this page directly. Thanks!'); if ( post_password_required() ) { ?> <p class="nocomments"><?php _e('This post is password protected. Enter the password to view comments.', 'kubrick'); ?></p> <?php return; } ?> <!-- You can start editing here. --> <?php if ( have_comments() ) : ?> <h3 id="comments"><?php comments_number(__('No Responses', 'kubrick'), __('One Response', 'kubrick'), __('% Responses', 'kubrick'));?> <?php printf(__('to “%s”', 'kubrick'), the_title('', '', false)); ?></h3> <div class="navigation"> <div class="alignleft"><?php previous_comments_link() ?></div> <div class="alignright"><?php next_comments_link() ?></div> </div> <ol class="commentlist"> <?php wp_list_comments();?> </ol> <div class="navigation"> <div class="alignleft"><?php previous_comments_link() ?></div> <div class="alignright"><?php next_comments_link() ?></div> </div> <?php else : // this is displayed if there are no comments so far ?> <?php if ( comments_open() ) : ?> <!-- If comments are open, but there are no comments. --> <?php else : // comments are closed ?> <!-- If comments are closed. --> <p class="nocomments"><?php _e('Comments are closed.', 'kubrick'); ?></p> <?php endif; ?> <?php endif; ?> <?php if ( comments_open() ) : ?> <div id="respond"> <h3><?php comment_form_title( __('Leave a Reply', 'kubrick'), __('Leave a Reply for %s' , 'kubrick') ); ?></h3> <div id="cancel-comment-reply"> <small><?php cancel_comment_reply_link() ?></small> </div> <?php if ( get_option('comment_registration') && !is_user_logged_in() ) : ?> <p><?php printf(__('You must be <a href="%s">logged in</a> to post a comment.', 'kubrick'), wp_login_url( get_permalink() )); ?></p> <?php else : ?> <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform"> <?php if ( is_user_logged_in() ) : ?> <p><?php printf(__('Logged in as <a href="%1$s">%2$s</a>.', 'kubrick'), get_option('siteurl') . '/wp-admin/profile.php', $user_identity); ?> <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="<?php _e('Log out of this account', 'kubrick'); ?>"><?php _e('Log out &raquo;', 'kubrick'); ?></a></p> <?php else : ?> <p><input type="text" name="author" id="author" value="<?php echo esc_attr($comment_author); ?>" size="22" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?> /> <label for="author"><small><?php _e('Name', 'kubrick'); ?> <?php if ($req) _e("(required)", "kubrick"); ?></small></label></p> <p><input type="text" name="email" id="email" value="<?php echo esc_attr($comment_author_email); ?>" size="22" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?> /> <label for="email"><small><?php _e('Mail (will not be published)', 'kubrick'); ?> <?php if ($req) _e("(required)", "kubrick"); ?></small></label></p> <p><input type="text" name="url" id="url" value="<?php echo esc_attr($comment_author_url); ?>" size="22" tabindex="3" /> <label for="url"><small><?php _e('Website', 'kubrick'); ?></small></label></p> <?php endif; ?> <!--<p><small><?php printf(__('<strong>XHTML:</strong> You can use these tags: <code>%s</code>', 'kubrick'), allowed_tags()); ?></small></p>--> <p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p> <p><input name="submit" type="submit" id="submit" tabindex="5" value="<?php _e('Submit Comment', 'kubrick'); ?>" /> <?php comment_id_fields(); ?> </p> <?php do_action('comment_form', $post->ID); ?> </form> <?php endif; // If registration required and not logged in ?> </div> <?php endif; // if you delete this the sky will fall on your head ?>

    • ベストアンサー
    • PHP