我在wordpress的一个页面上分配了一个自定义模板,但在启用永久链接后,它就不再工作了。使用“post type archive portfolio”模板代替自定义模板。
此自定义模板用于显示所有帖子(自定义类型帖子)。我已经检查了我的htaccess文件,我一次又一次地尝试启用禁用永久链接,但这些都不起作用。
这是创建自定义帖子类型和分类的模板文件和代码。
Custom post type creation:
/* Portfolio Custom Posts */
register_post_type( \'portfolio\', /* this can be seen at the URL as a parameter and a unique id for the custom post */
array(
\'labels\' => array(
\'name\' => __( \'Portfolio\',\'textdomain_simple\' ), /* The Label of the custom post */
\'singular_name\' => __( "All Portfolio", \'textdomain_simple\' ) /* The Label of the custom post */
),
\'public\' => true,
\'has_archive\' => true,
\'rewrite\' => array(\'slug\' => \'portfolio\'), /* The slug of the custom post */
\'supports\' => array( \'title\', \'thumbnail\', \'editor\', \'custom-fields\', \'revisions\' ), /* enable basic for text editing */
)
);
/* Portfolio Taxonomies/Categories */
function portfolio_taxonomie() {
register_taxonomy(
\'portfolio_category\',
array( \'portfolio\' ),
array(
\'public\' => true,
\'show_ui\' => true,
\'show_tagcloud\' => false,
\'hierarchical\' => true,
\'with_front\' => false,
\'labels\' => array(
\'name\' => __( \'Portfolio Category\', \'textdomain_topbest\' ),
\'singular_name\' => __( \'Porfolio Category\', \'textdomain_topbest\' )
),
)
);
register_taxonomy_for_object_type( \'post_tag\', \'portfolio\' );
}
add_action( \'init\', \'portfolio_taxonomie\', 0 );
function custom_post_type_tags( $query ) {
if ( !is_admin() && $query->is_tag() && $query->is_main_query() ) {
$query->set( \'post_type\', array( \'post\', \'portfolio\' ) );
}
}
add_action( \'pre_get_posts\', \'custom_post_type_tags\' );
Template file:
<?php /* Template Name: Portfolio Page */ ?>
<?php get_header(); ?>
<!-- Start main content -->
<div class="container main-content clearfix">
<div id="intro">
<blockquote><?php the_field(\'intro_message\'); ?></blockquote>
</div>
<div class="portfolio">
<div class="sixteen columns">
<div class="title clearfix" id="options">
<span>Filter:</span>
<ul id="filters" class="option-set clearfix" data-option-key="filter">
<li><a href="#filter" data-option-value="*" class="selected">All Projects</a></li>
<?php
$terms = get_terms("portfolio_category");
$count = count($terms);
if ( $count > 0 ){
foreach ( $terms as $term ) {
echo \'<li><a href="#filter" data-option-value=".\'.$term->slug.\'">\'.$term->name.\'</a></li>\';
}
}
?>
</ul>
</div>
</div> <!-- End options -->
<div class="clearfix"></div>
<div id="contain">
<!-- =================================================== -->
<?php
$args = array( \'numberposts\' => -1, \'order\'=> \'DESC\', \'post_type\' => \'portfolio\');
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post);
$terms = get_the_terms( $post->ID, \'portfolio_category\' );
if ( $terms && ! is_wp_error( $terms ) ) :
$term_links = array();
foreach ( $terms as $term ) {
$term_links[] = $term->slug;
}
$the_term = join( " ", $term_links );
$the_term_separated = join( ", ", $term_links );
?>
<?php if( has_post_thumbnail() ){ ?>
<!-- Start Portfolio Item -->
<div class="one-third column item element-3 <?php echo $the_term; ?>" data-categories="<?php echo $the_term; ?>">
<a href="<?php echo get_permalink(); ?>">
<?php the_post_thumbnail(\'portfolio-thumb\'); ?>
</a>
<div class="info">
<h3><?php echo vp_metabox(\'portfolio_option.list_title\'); ?>.</h3>
<a class="more" href="<?php echo get_permalink(); ?>"> Find out more »</a>
</div>
</div>
<!-- End Portfolio Item -->
<?php } ?>
<?php endif; ?>
<?php wp_reset_query(); endforeach; ?>
<!-- =================================================== -->
</div><!-- End contain-->
</div><!-- End portfolio -->
</div><!-- <<< End Container >>> -->
<?php get_footer(); ?>
你知道这是什么原因吗?