Как встроить новые метаданные записи для постов Wordpress, которые фактически отображаются на главной странице - PullRequest
0 голосов
/ 25 апреля 2020

Я пытаюсь создать новую метаданные записи для постов Wordpress, которая будет счетчиком посетителей, все готово, все работает, когда я go перехожу на страницу с постами, категорией, счетчиками посетителей. показано так: enter image description here

          This is the code for it:
          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 issues with prefetching adding extra views
         remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
            Now I add the following line of code in single.php file within the loop. 
           It will track the views and set the views of each post.
            setPostViews(get_the_ID());

         Now at the last step I use the following line of code where I want to display
         the view number inside the loop
         It will get the post view number from the last step where I call
         the set function to track the post views.

         echo getPostViews(get_the_ID());

Проблема в том, что домашняя страница связана с тем, что домашняя страница не является реальной страницей, но как я могу реализовать эту запись? данные для отображения на домашней странице, где я должен поместить это эхо getPostViews (get_the_ID ()); в папке wp помогите пожалуйста

...