将序数后缀添加到WordPress计数器 [英] Add Ordinal Suffix to WordPress Counter

查看:96
本文介绍了将序数后缀添加到WordPress计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向要为排名委员会构建的WordPress Post Counter添加序数后缀.这是我目前拥有的代码.

I am trying to add ordinal suffixes to a WordPress Post Counter that I am building for a ranking board. Here is the code I currently have.

<?php if(have_posts()): $counter = 1; query_posts('post_type=rushmoor&meta_key=subaru_driver_best_lap&orderby=meta_value_num&order=asc'); while(have_posts()):the_post();?>
<?php $driver_best_lap = get_post_meta( get_the_ID(), 'subaru_driver_best_lap', true );?>
<li>
    <div class="name"><?php echo $counter;?> <?php the_title();?></div>
    <div class="lap-time"><?php echo $driver_best_lap;?></div>
</li>         
<?php $counter++; endwhile; wp_reset_query(); endif;?>

我一直在尝试通过以下链接与上面的代码合并代码,但是我无法提供任何有效的方法,并且想知道是否有人可以提供帮助.

I have been trying to merge code from the following link with the above, however I cannot yield anything that actually works and am wondering if anyone can assist.

添加'rd或'th或'st依赖于号码

谢谢 扎克

推荐答案

您要从其他答案中添加ordinal_suffix函数到您的WordPress functions.php 文件,以便您可以在主题中使用它.然后,您要将您的$counter输出传递给它.您需要将该行更改为:

You want to add the ordinal_suffix function from the other answer to your WordPress functions.php file so you can use it in your theme. Then you want to pass your $counter output to it. You'll want to change that line to:

<div class="name"><?php echo ordinal_suffix($counter);?> <?php the_title();?></div>

这篇关于将序数后缀添加到WordPress计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆