我有一個自定義帖子類型,我試圖顯示一個類別頁面,所以當你點擊標準鏈接到一個類別時,你會看到該類別中的所有帖子..這看起來很簡單,我已經看了Wordpress的層次結構,但我不知道我需要創建哪些模板文件...添加類別頁面 - CPT - Wordpress
我目前有這個網頁拉動我的自定義字段:http://ideedev.co.uk/newseed/brand/不循環自定義帖子類型。該代碼基本上是這樣的:
<?php
/**
* Template name: Main Category Template
*/
?>
<?php get_header(); the_post(); ?>
<!-- Featured Image =========================================== -->
<div class="image-test-container">
<?php if (has_post_thumbnail()) {
// Get the post thumbnail URL
$feat_image = wp_get_attachment_url(get_post_thumbnail_id($post->ID));
} else {
?>
<style type="text/css">.featured-image{
display:none;
}</style>
<?php
} ?>
<div id="absolute1111" style=" background: url(<?php echo $feat_image; ?>);">
<div class="centerd1111">
<h1><?php the_title(); ?></h1>
</div>
</div>
</div>
<!-- Page Content =========================================== -->
<div class="container">
<div class="row clearfix">
<div class="">
</div>
</div>
<div class="row clearfix">
<div class="level-two-intro-text">
<p><?php the_field('intro_text'); ?></p>
</div>
<div class="level-two-sub-title block__title">
<?php the_field('sub_title'); ?>
</div>
</div>
</div>
<!-- Areas =========================================== -->
<div class="container">
<div class="row clearfix">
<?php if(get_field('areas')): ?>
<?php while(has_sub_field('areas')): ?>
<div class="single-area-item six columns">
<p> <img src="<?php the_sub_field('area_icon'); ?>" style="width:100%;"> <p>
<h2> <?php the_sub_field('area_title'); ?> </h2>
<p> <?php the_sub_field('area_info'); ?> <p>
<div class="area-button"><a href="<?php the_sub_field('button_target'); ?>" class="btn btn--dark-blue" role="button"><?php the_sub_field('button_text'); ?></a></div>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
然而,當我在投資組合鍵單擊每個類別下,我想它顯示該類別的網頁...
我可以做這個工作爲每個類別創建一個單獨的模板頁面,並循環顯示特定類別中的所有帖子,但這似乎是錯誤的方式 - 我認爲應該有一個模板來顯示我剛纔單擊的類別...
我覺得我有點困惑,說實話。爲尋找謝謝:)
+++編輯+++
下面是我使用自定義職位類型的代碼...
register_post_type('portfolio', $args);
// Portfolio Categories
$labels = array(
'name' => _x('Portfolio Categories', 'taxonomy general name'),
'singular_name' => _x('Portfolio Category', 'taxonomy singular name'),
'search_items' => __('Search Portfolio Categories'),
'all_items' => __('All Portfolio Categories'),
'parent_item' => __('Parent Portfolio Category'),
'parent_item_colon' => __('Parent Portfolio Category:'),
'edit_item' => __('Edit Portfolio Category'),
'update_item' => __('Update Portfolio Category'),
'add_new_item' => __('Add New Portfolio Category'),
'new_item_name' => __('New Portfolio Category Name'),
'menu_name' => __('Portfolio Category'),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'category'),
);
register_taxonomy('portfolio-category', array('portfolio'), $args);
嗨,你好,您使用的自定義後類型的默認類別太?或定製分類? – Ashkar
這是定製 - 它被稱爲投資組合類別,所以我可以保持它與博客和其他項目我分開... –
我會將CPT文本添加到問題,如果有幫助... –