WordPress 随机获取热门标签方法

Kevin 杂记 1,004 次浏览 27条评论

制作WP主题时遇到的一个需求,要在热门文章标签里随机获取标签。实现方法如下,将下面功能代码放入 functions.php 文件,然后使用<?php get_random_hot_tags(); ?>调用即可。

 * 获取随机热门标签
function get_random_hot_tags() {
    $args = array('number' => '9', 'orderby' => 'count', 'order' => 'DESC'); // 从最多文章的9个标签内获取
    $hot_tag_list = get_tags( $args ); // 获取标签列表
    shuffle($hot_tag_list); // 添加随机排序
    $count=0; // 初始计数值
    if ($hot_tag_list) {
       foreach($hot_tag_list as $tag) { // 数组遍历
       $count++; // 开始递归计数
       echo '<a href="'.get_tag_link($tag->term_id).'" title="' . $tag->count . ' 篇文章">'.$tag->name.'</a>';
       if( $count === 3 ) break; // 获取3个标签后停止循环
    else {
       echo '<span>暂无数据</span>'; // 若没有标签提示信息


  1. #1

    acyclovir treatment for cold sores https://www.herpessymptomsinmen.org/productacyclovir/

  2. #2

    can hydroxychloroquine prevent coronavirus https://hydroxychloroquine.webbfenix.com/

  3. #3

    ivermectin dosage for humans chart https://ivermectin.webbfenix.com/

  4. #4

    low dose naltrexone autoimmune in pediatric patients https://naltrexoneonline.confrancisyalgomas.com/

  5. #5

    liquid vidalista citrate https://vidalista.buszcentrum.com/

  6. #6

    red viagra pills http://droga5.net/

  7. #7

    does dapoxetine work for diabetics https://salemeds24.wixsite.com/dapoxetine

  8. #8

    tadalafil vs silagra dosing https://silagra.buszcentrum.com/

  9. #9

    lowest price vidalista https://vidalista.mlsmalta.com/

  10. #10

    order hydroxychloroquine online canada https://hydroxychloroquine.mlsmalta.com/

  11. #11

    side effects from keflex antibiotics https://keflex.webbfenix.com/

  12. #12

    generic suhagra in the usa https://suhagra.buszcentrum.com/

  13. #13

    stromectol and alcohol https://ivermectin.mlsmalta.com/

  14. #14

    is vidalista from mexico authentic https://vidalista40mg.mlsmalta.com/

  15. #15

    dapoxetine 60mg coupon https://ddapoxetine.com/

  16. #16

    tadalafil ed medication https://tadalafili.com/

  17. #17

    tadalafil tablets 20 mg cost https://wisig.org/

  18. #18

    doxycycline hyclate 20 mg acne http://doxycycline.zolftgenwell.org/

  19. #19

    generic albuterol inhaler now available https://amstyles.com/

  20. #20

    can cenforce pills be cut http://cavalrymenforromney.com/

  21. #21

    hydroxychloroquine works https://hydroxychloroquinee.com/

  22. #22

    Utterly composed written content, regards for selective information. “The bravest thing you can do when you are not brave is to profess courage and act accordingly.” by Corra Harris.


  23. #23

    I am also writing to make you know what a incredible encounter my friend’s girl gained reading through your web page. She learned plenty of pieces, which include what it’s like to possess an amazing helping mood to let other folks smoothly know just exactly several multifaceted subject matter. You truly exceeded our own expectations. Thank you for offering these necessary, safe, explanatory and even fun tips about this topic to Julie. https://johnpisanohomeimprovements.com/

  24. #24

    I am also commenting to let you know of the helpful encounter my friend’s daughter found reading through your web page. She figured out numerous issues, not to mention what it’s like to have an amazing giving mood to have most people really easily know selected impossible subject areas. You really exceeded our own expectations. Many thanks for imparting the invaluable, safe, explanatory and even easy thoughts on the topic to Janet. https://hillsdaledowcenter.com/

  25. #25

    cialis online without prescription http://cialllis.com/

  26. #26

    I enjoy you because of all of your effort on this blog. Ellie enjoys conducting internet research and it’s easy to see why. All of us hear all about the compelling manner you create efficient ideas by means of the blog and as well cause contribution from other ones about this article and my child is being taught a great deal. Enjoy the remaining portion of the new year. You’re the one carrying out a fantastic job. https://endepamitriptyline.com/

  27. #27

    Thanks for the tips on credit repair on all of this blog. What I would advice people is to give up the mentality that they can buy now and pay later. As a society we tend to do this for many things. This includes vacations, furniture, and items we want. However, you need to separate your wants from all the needs. While you are working to improve your credit score you have to make some sacrifices. For example you can shop online to save money or you can go to second hand stores instead of expensive department stores for clothing. https://zyprexaolanzapine.com/#


电邮地址用于 Gravatar 头像显示,不会被公开可见。