客户贴内页不带单库.php吗?IT重定向至存档页面

时间:2017-11-28 作者:anup singh
<?php
//----------------------------------------------
//----------register and label gallery post type
//----------------------------------------------
$gallery_labels = array(
\'name\' => _x(\'Gallery\', \'post type general name\'),
\'singular_name\' => _x(\'Gallery\', \'post type singular name\'),
\'add_new\' => _x(\'Add New\', \'gallery\'),
\'add_new_item\' => __("Add New Gallery"),
\'edit_item\' => __("Edit Gallery"),
\'new_item\' => __("New Gallery"),
\'view_item\' => __("View Gallery"),
\'search_items\' => __("Search Gallery"),
\'not_found\' =>  __(\'No galleries found\'),
\'not_found_in_trash\' => __(\'No galleries found in Trash\'), 
\'parent_item_colon\' => \'\'

);

$gallery_args = array(
\'labels\' => $gallery_labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true, 
\'query_var\' => true,
\'rewrite\' => true,
\'hierarchical\' => true,
\'menu_position\' => null,
\'capability_type\' => \'post\',
\'supports\' => array(\'title\', \'excerpt\', \'editor\', \'thumbnail\'),
\'menu_icon\' => \'dashicons-vault\' //16x16 png if you want an icon
 ); 

 register_post_type(\'gallery\', $gallery_args);
 //----------------------------------------------
 //------------------------create custom taxonomy
 //----------------------------------------------
 add_action( \'init\', \'jss_create_gallery_taxonomies\', 0);

 function jss_create_gallery_taxonomies(){
   register_taxonomy(
    \'phototype\', \'gallery\', 
    array(
        \'hierarchical\'=> true, 
        \'label\' => \'Photo Types\',
        \'singular_label\' => \'Photo Type\',
        \'rewrite\' => true
       )
  );    
}
?>

/***************************************************************/
<ul class="photo-gallery-page">
<?php
  $args = array(
           \'post_type\'  => \'gallery\',
           \'taxonomy\' => \'phototype\',
           \'orderby\' => \'name\',
           \'order\'   => \'ASC\'
       );

    $cats = get_categories($args);

   foreach($cats as $cat) {
  ?>
   <li class="stack twisted col-lg-3 col-md-3 col-sm-3 col-xs-12 gal_pad" >
     <div id="gallery_image">
       <a href="<?php echo get_category_link( $cat->term_id ) ?>">
         <?php echo $cat->name; ?>
       </a>
     </div>
   </li>
<?php
    wp_reset_postdata();  }
  ?>
</ul>   
1 个回复
SO网友:Ankita Tanti

get_categories() 函数检索类别对象的列表,您将在类别中循环,而不是在自定义帖子中循环。因此,此处发布的代码将回应类别链接,而不是单个自定义帖子链接。

当您尚未创建任何自定义分类法模板时,默认情况下,它会将其绑定到存档。php

有关模板层次结构的更多信息,请访问:https://developer.wordpress.org/themes/basics/template-hierarchy/

如果您回显自定义帖子链接,那么它会将其绑定到single-gallery.php. 要创建自定义分类法模板,需要将其绑定到taxonomy-{taxonomy}.php

希望这对你有帮助!

结束

相关推荐

由于筛选器的原因,Get_Posts()中断

“我的自定义帖子类型(works)”的“我的列表视图”页面上有一个筛选器add_action( \'pre_get_posts\', array($this, \'exclude_category\') ); public function exclude_category( $query){ if( is_admin() && isset( $_GET[\'cta_filter\']) && ! empty( $_GET[