Single-{post-type}.php在WordPress中不起作用

时间:2017-04-11 作者:Nayeem Hyder Riddhi

我的单发-{post type}。php不工作。这是基于最近工作或项目的自定义帖子类型。当我单击永久链接时,它不会转到单个项目。php,它会转到主页或索引页。请提供任何解决方案。

Register post type:

 //Custom post for Recent work
    function projects_post_type() {

             register_post_type( \'projects\',
     array(
    \'labels\' => array(
     \'name\' => __( \'Recent Work\' ),
     \'singular_name\' => __( \'Recent Work\' ),
     \'add_new\' => __( \'Add New\' ),
     \'add_new_item\' => __( \'Add New work\' ),
     \'edit_item\' => __( \'Edit work\' ),
     \'new_item\' => __( \'New work\' ),
     \'view_item\' => __( \'View work\' ),
     \'not_found\' => __( \'Sorry, we couldn\\\'t find the work you are looking for.\' )
                ),

    \'public\' => true,
    \'publicly_queryable\' => false,
    \'exclude_from_search\' => true,
    \'menu_position\' => 14,
    \'has_archive\' => false,
    \'hierarchical\' => false, 
    \'capability_type\' => \'page\',
    \'rewrite\' => array( \'slug\' => \'projects\' ),
   \'supports\' => array(\'title\')
            )
        );

             register_taxonomy(
         \'filtering_category\',
         \'projects\',
     array (
         \'labels\' => array(
         \'name\' => \'Filter Category\',
         \'add_new_item\' => \' Add New Filter Category\'
            ),
         \'hierarchical\' => true,
         \'show_admin_column\' => true
              ) );

    }

add_action( \'init\', \'projects_post_type\' );

Portfolio Page:

         <?php

                            $args = array(
                            \'post_type\' => \'projects\',
                            \'posts_per_page\' => \'-1\',
                              );
                             // the query
                             $query = new WP_Query( $args );
                              // The Loop   
                             if ( $query->have_posts() )  ?>
               <?php while ( $query->have_posts() ) : $query->the_post() ; ?>

                    <div class="portfolio logo" data-cat="logo">
                        <div class="portfolio-wrapper">
                            <div class="portfolio-hover">
                                <div class="image-caption">

<a href="<?php echo get_post_meta(get_the_ID(), \'work_photo\', true); ?>" class="label magnefig label-info icon" data-toggle="tooltip" data-placement="left" title="Zoom"><i class="fa fa-eye"></i></a>

<a href="<?php the_permalink();  ?>" class="label label-info icon" data-toggle="tooltip" data-placement="top" title="Details"><i class="fa fa-link"></i></a>
                                    </a>

                            </div>
 <img src="<?php echo get_post_meta(get_the_ID(), \'work_photo\', true); ?>" alt="" />

                        </div>
                    </div>
                </div>


             <?php endwhile;   ?>

1 个回复
最合适的回答,由SO网友:Nayeem Hyder Riddhi 整理而成

它现在正在工作,我已经更改了注册帖子类型全部为真,现在正在工作

相关推荐