将类别添加到当前的Wordpress帖子标题

编程入门 行业动态 更新时间:2024-10-25 16:25:00
本文介绍了将类别添加到当前的Wordpress帖子标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在研究服务cpt,并希望在单个帖子的同一cpt中显示其他帖子的列表。

I am working on a services cpt and would like to display a list of other posts, within the same cpt on the single post.

我正在使用的代码是:

<?php $loop = new WP_Query( array( 'post_type' => 'services', 'posts_per_page' => 6 )); ?> <ul> <?php while ( $loop->have_posts() ) : $loop->the_post(); ?> <li> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> <h4><?php the_title(); ?></h4> </a> </li> <?php endwhile; wp_reset_query(); ?> </ul>

现在我的问题是,有没有办法在当前帖子中添加一个类?目的是使其样式与列表中的其他帖子不同。

Now my question is, is there a way to add a class to the current post? The intention being to style it different to the other posts in the list.

推荐答案

这很容易,您可以随时添加类在

This is very easy you can always add the class in before and after

阅读本文档 developer.wordpress/reference/functions/the_title/

<?php the_title( '<div class="wrapper">', '</div>' ); ?>

更多推荐

将类别添加到当前的Wordpress帖子标题

本文发布于:2023-10-12 17:30:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485387.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类别   标题   帖子   Wordpress

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!