【问题标题】:style listing wordpress 2 custom post types and 1 taxonomie样式列表 wordpress 2 个自定义帖子类型和 1 个分类法
【发布时间】:2013-07-20 07:12:02
【问题描述】:

我已经开发了一个基于 2 种自定义帖子类型的供应商目录,共享相同的分类,非常好,在我的主页上我显示了一个供注册广告商访问的术语列表,就像

Screenshot 1

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

问题从这里开始。

我得到一个页面,其中包含任何自定义帖子类型中的注册广告商列表,但我希望根据自定义帖子类型,每个列表都有其风格...

Screenshot 2

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

在截图 2 中,示例... Oscar Navarro 已在自定义帖子类型“basico”中注册,“Carlos Galarza Fotografía”已在自定义帖子类型“directorio”中注册。

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

【问题讨论】:

    标签: wordpress custom-post-type taxonomy


    【解决方案1】:

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

    请检查内容模板部分

    尝试如下修改模板部分

    <?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;
    }
    

    【讨论】:

    • as... 这段代码寻找... style-basico.php 和 style-directorio.php ??? TNXS!
    • 你不能那样做。在 get_template_part() 内部,你需要检查 post_type.not 之前 .... 在 get_template_part() 内部开始循环;
    猜你喜欢
    • 1970-01-01
    • 2013-08-03
    • 2015-03-15
    • 1970-01-01
    • 2013-06-22
    • 1970-01-01
    • 2014-07-10
    • 2014-10-23
    • 2014-09-01
    相关资源
    最近更新 更多