###前提・実現したいこと
podsで作成されたページの、人気ページのランキング表示をしたいです。
WPプラグイン「Podshttps://ja.wordpress.org/plugins/pods/」を使用しています。
podsでは、advanced content typeを使用し、
https://pods.io/docs/build/how-to-create-an-advanced-content-type/
pods pageで表示しています。
https://pods.io/docs/comparisons/compare-wp-pages-to-pod-pages/
podsで作成されたページの、人気ページのランキング表示をしたいです。
###発生している問題・エラーメッセージ
WordPress Popular Postsでの利用を考えておりましたが、
取得対象が、postかpageになってしまうため、記事の取得ができませんでした。
###試したコードは下記です。
<?php if (function_exists('wpp_get_mostpopular')) { $sidetest=pods('users', array( 'where' => "pods_field_name", )); $options = array( 'limit' => 5, // 表示件数の指定 'range' => 'monthly', // 集計期間 'daily', 'weekly', 'monthly', 'all' 'order_by' => 'views', // 集計の並び替え 'comments', 'views', 'avg' 'post_type' => 'page', // 集計対象指定 'wpp_start' => '<div class="side_rank_list"><ul>', 'wpp_end=' => '</ul></div>', 'post_html' => '<li><div class="list clearfix"><a href="https://xx/'.$sidetest->display("permalink").'" class="thmb"> <img src="'.$ctm.'" width="150" height="150" alt="" class="wpp-thumbnail wpp_def_noPath wpp_first_attachment"></a><div class="views">{view}</div><a href="https://xx'.$sidetest->display("permalink").'"><h4><strong>'.$sidetest->display( 'office' ).'<br></strong><div class="icon">'.$sidetest->display( 'shimei' ).'</div></h4></a></div></li>', ); wpp_get_mostpopular($options); } ?>
###現在試していること
プラグインなしでのランキング表示が必要かと思い、下記をコードを参照に試そうとしたのですが、
podsのフィールドにカウント数の追加方法がわからず、難航しています。
参考
『プラグインなし』で人気記事一覧を出力する方法
https://manablog.org/wordpress-popular-posts-without-plugin/
// 人気記事出力用 function getPostViews($postID){ $count_key = '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'; } function setPostViews($postID) { $count_key = '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);
どうかよろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。