简体   繁体   English

如何随机排序WordPress的“链接”和“类别”

[英]How to sort Wordpress “links” and “categories” random

A new client wants us to maintain his old website made by someone else. 一个新客户希望我们维护其他人创建的旧网站。 I currently have this code that I somehow can't get to work. 我目前有无法以某种方式工作的这段代码。 I want to make the output of the code show random. 我想使代码的输出显示随机。 Instead of an alphabetical order. 而不是字母顺序。 I've tried 'orderby' => 'rand'. 我试过了'orderby'=>'rand'。 But without luck. 但是没有运气。

<?php
      $bookmarks = get_bookmarks();
      if ($bookmarks != '') { ?>
         <?php foreach ( $bookmarks as $bookmark ) { ?>
         <a onclick="recordOutboundLink(this, 'Partners outgoing', '
<?php echo $bookmark->link_name; ?>');return true;" title="<?php echo $bookmark->link_name; ?>" href="<?php echo clean_url($bookmark->link_url); ?>" target="_blank" class="Allemaal grid3 partners 

<?php /* start van class --- hier de categorie oproepen en zonder spatie plaatsen*/
$term_list = wp_get_post_terms( $bookmark->link_id, 'link_category', array( 'fields' => 'all' )  );
foreach($term_list as $term_single) {
$getterm2 = $term_single->name;
$getterm3 = str_replace(' ', '', $getterm2);
echo ' ';
echo $getterm3;
}
/* einde van class ---hier de categorie oproepen en zonder spatie plaatsen*/
?>">

<img src="<?php echo $bookmark->link_image ?>">
<p><?php echo $bookmark->link_name; ?></p>
</a>

    <?php } ?>
<?php } ?>

To see this in action you can go here 要查看此功能,可以转到此处

Can someone point me in the right direction? 有人可以指出我正确的方向吗?

只需在foreach循环之前执行shuffle($term_list)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM