[英]Related Posts with Numbers Wordpress
I want to add numbers in posts to get the output below: 我想在帖子中添加数字以获取以下输出:
<?php
$args= array(
'posts_per_page'=>8,
'date_query' => array(
array(
'year' => date( 'Y' ),
'week' => date( 'W' ),
),
),
'meta_key' => 'popular_posts',
'order' => 'DESC',
'orderby' => 'meta_value_num'
);
$i=0;
$funLoop = new WP_Query( $args );
while ($funLoop -> have_posts() ) : $funLoop->the_post(); $i++;
$cat = get_the_category($post->ID)[0];
?>
<div class="small-12 medium-6 columns unpadded"> <article class="small-12 med columns articles-<?php echo$cat->slug; ?>"> <a href="<?php the_permalink();?>"> <div class="number"> 1. </div>
The best method is to wrap your content in <ol>
. 最好的方法是将您的内容包装在
<ol>
。 But if you cant you can make usage of the css counter. 但是,如果不能,则可以使用css计数器。
Example: Your html: 示例:您的html:
<div class="small-12 medium-6 columns unpadded">
<article class="small-12 med columns articles-<?php echo$cat->slug; ?>">
<a href="<?php the_permalink();?>">
<div class="number">
</div>
</a>
<a href="<?php the_permalink();?>">
<div class="number">
</div>
</a>
<a href="<?php the_permalink();?>">
<div class="number">
</div>
</a>
</article>
CSS: CSS:
body {
counter-reset: mynum;
}
.artikulli a .number {
counter-increment: mynum;
}
.artikulli a .number:before {
content: counter(mynum)".";
}
Working codepen: https://codepen.io/anon/pen/VBgKrW 工作码本: https ://codepen.io/anon/pen/VBgKrW
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.