WordPress 随机获取热门标签方法

Kevin 杂记 1,229 次浏览 48条评论

制作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.

    http://www.vreyrolinomit.com/

  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/#

  28. #28

    cialis tablets 80 mg https://tadalafil.cleckleyfloors.com/

  29. #29

    cialis without a doctor prescription usa http://tadalafila.online/

  30. #30

    ivermectin without doctor visit http://ivermmectin.com/

  31. #31

    generic azithromycin without doctor visit http://aziithromycin.com/

  32. #32

    canadian happy family store pharmacy https://buymeds.mlsmalta.com/

  33. #33

    canadian happy family store pharmacy https://edmeds.buszcentrum.com/

  34. #34

    cialis cost https://cialzi.com/

  35. #35

    order vidalista online without prescription http://vidallista.com/

  36. #36

    cialis soft tabs uk https://www.lm360.us/

  37. #37

    generic cialis daily use https://cialis.stdstory.com/

  38. #38

    generic cialis daily use https://cialis.lm360.us/

  39. #39

    If you wish for to grow your experience only keep visiting this
    web page and be updated with the newest news update posted here. http://antiibioticsland.com/Cipro.htm

  40. #40

    Hello there I am so thrilled I found your site, I really found you by mistake, while I was looking on Digg for something else, Nonetheless I am here now
    and would just like to say thanks for a remarkable post and
    a all round interesting blog (I also love the theme/design), I don’t have time
    to read it all at the moment but I have book-marked it and also included your
    RSS feeds, so when I have time I will be back to read a lot
    more, Please do keep up the superb work. https://cialis.studiowestinc.com/tadalafil

  41. #41

    This is very interesting, You’re a very skilled blogger. I’ve
    joined your rss feed and look forward to seeking more of your great
    post. Also, I have shared your site in my social networks! https://hydroxychloroquinea.advantagetriseal.com/

  42. #42

    I have to thank you for the efforts you have put in writing this blog.

    I’m hoping to see the same high-grade blog posts from you later on as well.
    In fact, your creative writing abilities has
    inspired me to get my very own site now 😉 https://hydroxychloroquineb.bee-rich.com/

  43. #43

    Do you mind if I quote a few of your posts as long as I provide credit and sources back
    to your blog? My website is in the exact same area of interest as yours and my visitors would definitely benefit
    from a lot of the information you present here.
    Please let me know if this alright with you. Cheers! http://herreramedical.org/acyclovir

  44. #44

    I loved as much as you will receive carried out right here.
    The sketch is attractive, your authored subject matter stylish.
    nonetheless, you command get bought an edginess over
    that you wish be delivering the following.
    unwell unquestionably come more formerly again as exactly the same nearly very often inside case you shield this hike. http://www.deinformedvoters.org/aurogra-online

  45. #45

    mefloquine vs hydroxychloroquine https://hhydroxychloroquine.com/

  46. #46

    buy hydroxychloroquine online https://hydroxychloroquinex.com/

  47. #47

    I think this is one of the most important information for me. And i am glad reading your article. But wanna remark on few general things, The site style is wonderful, the articles is really excellent : D. Good job, cheers

    https://www.youtube.com/watch?v=yRUUMTPhLH0

  48. #48

    cialis best price uk buy tadalafil online how much is a cialis prescription http://www.tadalafill.online/

发表评论

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