样式列出wordpress 2自定义帖子类型和1分类

时间:2013-07-20 07:12:02

标签: wordpress custom-post-type taxonomy

我根据2种自定义帖子类型开发了供应商目录,共享相同的分类,非常好,在我的主页上,我显示了注册广告客户访问的条款列表,就像

Screenshot 1 enter image description here

一切都很好......但是....

此处启动问题。

我在任何自定义帖子类型中都会显示包含已注册广告客户列表的页面,但我希望这取决于自定义帖子类型,每个列表都有其风格...

Screenshot 2 enter image description here

名为“directorio”的自定义帖子类型的样式和名为“basico”的自定义帖子类型的不同样式共享分类法称为“categoria”

在截图2中,样本...... Oscar Navarro已在自定义帖子类型“basico”中注册,“CarlosGalarzaFotografía”已在自定义帖子类型“directorio”中注册。

是否可以为每个自定义帖子类型添加类,以便在css中使用不同的样式?

1 个答案:

答案 0 :(得分:0)

您可以在循环中检查帖子类型,并将课程添加到该帖子

请检查内容template_part

尝试修改模板部分,如下所示

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<?php
global $post;
                <span id="post-<?php the_ID(); ?>" <?php post_class(); ?>>


            <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
                <?php the_post_thumbnail('large');?>
            </a>
        </span>


<?php endwhile; // end of the loop. ?>

将此添加到function.php

add_filter( 'post_class','your_post_class' , 20, 3 );

    public function your_post_class( $classes, $class, $post_id ) {
        if ( 'basico' == get_post_type() ){
               $classes[] = 'basico_class';
            }elseif ( 'directorio' == get_post_type()){
               $classes[] = 'directorio_class';
            }
        return $classes;
}