doudao1950 2014-05-29 14:41
浏览 69

计算单击按钮以创建“Top Event”区域

I am working on a Tourism website which displays multiple tours. I am using WordPress and have created a custom post type called Tours.

Inside every tour is a Book Now button which is created as a custom meta box. The Book Now button contains a link to a Third Party Booking System.

What I am looking to do is create a field on the homepage to show the most popular tour of the week. This will be judged by the number of clicks on the Book Now button inside each tour.

So, anytime a user clicks Book Now for a certain tour in the week, a count will be set to that tour and the tour with the highest number over a week, sits as a link on the homepage.

How to get this working via JavaScript or PHP?

  • 写回答

2条回答 默认 最新

  • douye1876 2014-05-29 14:52
    关注

    Each link should have a class and unique identifier

    <a href="/some/trip/package-A" class="countable" data-id="package-A">Click</a>
    

    With jquery on the javascript side, you bind to the click event of your link.

    $('a.countable').click(function() {
         // get our trip identifier
         var identifier = $(this).attr('data-id');
         // ajax call to increment counter
         jQuery.post(
                '/counter.php',
                {track_id: identifier}
            );
        }
    });
    

    counter.php then received track_id as a $_POST variable and increments your counter somewhere (database / redis / etc..) by calling increment_counter(). You'll also need functionality to report the most popular by week / month / day / etc back out from your datastore. Since this can be data intensive, its best to do that via a cron script that generates the final output instead of doing that on every page request. At worst, you should cache the "Top X" results for some time (an hour, six hours, a day?).

     <?php
     // assumes integer ids, filter inputs appropriately
     $identifier = (int) $_POST['track_id']; 
    
     if (!empty($identifier)) {
          increment_counter($identifier);
     }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)