WP 如何为 category.php 中显示的内容赋予不同的样式

WP how do I give different style to the content displayed in category.php

如何使用在 Index.php 和 content.php 上显示的相同 'content',但在 [=] 中显示时分配给它的样式 class 完全不同9=]?我该如何指定它?

category.php

<section class="main">
            <div class="mod"><h5><?php printf( __( 'Recent %s &#92; ', 'twentytwelve' ), single_cat_title( '', false ) ); ?></h5></div>
            <ul id="franchise_list" class="tout_list">
    <?php if ( have_posts() ) : ?>
        <?php
        /* Start the Loop */
        while ( have_posts() ) : the_post();

            /* Include the post format-specific template for the content. If you want to
             * this in a child theme then include a file called called content-___.php
             * (where ___ is the post format) and that will be used instead.
             */
            get_template_part( 'content', get_post_format(), '<a class="franchise">' . single_cat_title() );

        endwhile;

        twentytwelve_content_nav( 'nav-below' );
        ?>

    <?php else : ?>
        <?php get_template_part( 'content', 'none' ); ?>
    <?php endif; ?>
        <?php wpbeginner_numeric_posts_nav(); ?>

首先,你使用的get_template_part()是错误的。您不能向其中添加 class。查看文档。这是正确的语法

get_template_part( $slug, $name ); 

如果您需要某个类别的自定义内容文件,您只需复制 content.php、重命名它 content-category.php、添加您的自定义 classes 并更改您需要更改的内容, 保存然后在 category.php 中更改此行

get_template_part( 'content', get_post_format(), '<a class="franchise">' . single_cat_title() );

至此

get_template_part( 'content', 'category' );