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

时间:2015-01-09 08:24:35

标签: php wordpress categories

如何使用相同的内容'在index.php和content.php上显示但在category.php中显示时为其分配了完全不同的样式类?我该如何指定它?

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(); ?>

1 个答案:

答案 0 :(得分:0)

首先,您使用的是get_template_part()错误。你不能为它添加类。看看文档。这是正确的语法

get_template_part( $slug, $name ); 

如果您需要某个类别的自定义内容文件,只需复制content.php,将其重命名为content-category.php,添加自定义类并更改需要更改的内容,保存后再放入{ {1}}更改此行

category.php

到这个

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