将类别添加到当前的Wordpress帖子标题 [英] Add class to current Wordpress Post Title

查看:62
本文介绍了将类别添加到当前的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

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

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

这篇关于将类别添加到当前的Wordpress帖子标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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