我正在設計一個使用Underscore主題作爲基礎的wordpress主題。我創建了一個名爲Projects的自定義帖子類型。下面是註冊後類型的代碼:WordPress模板系統不能與get_template_part配合使用
add_action('init', 'create_post_type');
function create_post_type() {
register_post_type('Projects',
array(
'labels' => array(
'name' => __('projects'),
'singular_name' => __('projects')
),
'taxonomies' => array('post_tag'),
'public' => true,
'has_archive' => true,
'supports' => array('title','editor','thumbnail','excerpt'),
)
);
}
所以,現在我創建了一個新的職位類型,我就去設計的職位類型的模板。由於下劃線使用get_template_type拉主題一起,我做了一個文件名爲單projects.php,其中包括以下代碼:
<?php
/**
* The Template for displaying all single posts.
*
* @package professional1d
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php while (have_posts()) : the_post(); ?>
<?php get_template_part('content', 'Projects'); ?>
<?php professional1d_content_nav('nav-below'); ?>
<?php
// If comments are open or we have at least one comment, load up the comment template
if (comments_open() || '0' != get_comments_number())
comments_template();
?>
<?php endwhile; // end of the loop. ?>
</main><!-- #main -->
</div><!-- #primary -->
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
然後,我創建了內容projects.php網頁,其中有對於實際的模板的代碼,這就是:
<?php
/**
* @package professional1d
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-meta">
<?php professional1d_posted_on(); ?>
</div><!-- .entry-meta -->
</header><!-- .entry-header -->
<div class="entry-content">
<p>
<img src="<?php
$thumb_id = get_post_thumbnail_id();
$thumb_url = wp_get_attachment_image_src($thumb_id,'thumbnail-size', true);
echo $thumb_url[0];
?>" class="img-thumbnail" align="left">
<strong><u><?php echo get_the_title(); ?></u></strong><br>
<strong>Date: </strong>
<?php the_field('start_date'); ?>
<?php
if(get_field('end_date')){
echo ' - ' . get_field('end_date') .;
}
?><br>
<strong>Type: </strong> <?php the_field('type'); ?><br>
<strong>Status: </strong> <?php the_field('status'); ?>
</p>
<div class="sexy_line"></div>
<?php the_content(); ?>
<?php
wp_link_pages(array(
'before' => '<div class="page-links">' . __('Pages:', 'professional1d'),
'after' => '</div>',
));
?>
</div><!-- .entry-content -->
<footer class="entry-meta">
<?php
/* translators: used between list items, there is a space after the comma */
$category_list = get_the_category_list(__(', ', 'professional1d'));
/* translators: used between list items, there is a space after the comma */
$tag_list = get_the_tag_list('', __(', ', 'professional1d'));
if (! professional1d_categorized_blog()) {
// This blog only has 1 category so we just need to worry about tags in the meta text
if ('' != $tag_list) {
$meta_text = __('This entry was tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'professional1d');
} else {
$meta_text = __('Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'professional1d');
}
} else {
// But this blog has loads of categories so we should probably display them here
if ('' != $tag_list) {
$meta_text = __('This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'professional1d');
} else {
$meta_text = __('This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'professional1d');
}
} // end check for categories on this blog
printf(
$meta_text,
$category_list,
$tag_list,
get_permalink(),
the_title_attribute('echo=0')
);
?>
<?php edit_post_link(__('Edit', 'professional1d'), '<span class="edit-link">', '</span>'); ?>
</footer><!-- .entry-meta -->
</article><!-- #post-## -->
</div>
我想我遵循了正確的協議,使模板的工作,但由於某些原因,當我打開項目的職位之一,隨着內容的頁面帖子確實出現,但它沒有使用t我在content-projects.php文件中設計了模板。您可以在這裏看到問題的實際情況:http://onedirectionconnection.com/tester/?projects=take-me-home-tour正如您所看到的,我上面粘貼的模板未被使用。
此外,我嘗試在single-projects.php文件中將項目中的P降低,但後面的內容剛剛消失。
single.php和content-single.php使用相同的方法,它正在爲那對工作。任何人都可以向我提供一些有關我在做什麼錯誤的見解嗎?
讓我知道你是否需要更多的信息或代碼!
感謝您的時間和幫助。
感謝您的輸入!我做了這些更改(將項目更改爲小寫,然後在函數文件中更改它)。但現在當你去一個項目頁面,只有標題顯示:http://onedirectionconnection.com/tester/projects/take-me-home-tour/ – nellygrl
也許這是永久鏈接...你的意思是改變永久鏈接後臺下設置>>固定鏈接?如果是這樣,你的意思是哪個永久鏈接結構? – nellygrl
你不必改變你的永久鏈接結構,只需重新保存你在設置 - >永久鏈接中的內容。 – Peter