我创建了一个名为“食谱”的自定义帖子类型,但是我的帖子显示为“找不到页面”。
这是我创建的帖子之一的链接-http://pt1-dev.info/recipes/festive-napa-cabbage/,但显示为找不到页面。
我的主题也没有显示在我的页面上。 (这只是一个测试站点,因此只能显示导航和页脚框)
这是我的代码-
// Register Custom Post Types
add_action('init', 'register_custom_posts_init');
function register_custom_posts_init() {
// Register Recipes
$recipes_labels = array(
'name' => 'Recipes',
'singular_name' => 'Recipe',
'menu_name' => 'Recipes'
);
$recipes_args = array(
'labels' => $recipes_labels,
'public' => true,
'capability_type' => 'post',
'show_in_menu' => true,
'show_in_nav_menus' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions' )
);
register_post_type('recipes', $recipes_args);
}
add_action( 'init', 'custom_post_type', 0 );
function tr_create_my_taxonomy() {
register_taxonomy(
'recipes-category',
'recipes',
array(
'label' => __( 'Recipe Category' ),
'rewrite' => array( 'slug' => 'recipes-category' ),
'hierarchical' => true,
)
);
}
add_action( 'init', 'tr_create_my_taxonomy' );
这就是我创建的配方文件php-
<?php
// Posts are found
if ( $posts->have_posts() ) {
while ( $posts->have_posts() ) :
$posts->the_post();
global $post;
?>
$args = array(
'post_type' => 'recipes',
'post_status' => 'publish',
'posts_per_page' => '10'
);
$recipes_loop = new WP_Query( $args );
if ( $recipes_loop->have_posts() ) :
while ( $recipes_loop->have_posts() ) : $recipes_loop->the_post();
// Set variables
$title = get_the_title();
$description = get_the_content();
$recipeby = get_field('recipe_by');
$category = get_field('category');
$recipe_description = get_field('recipe_description');
$image = get_field('recipe_image');
if (!empty($image)) {
$url = get_field('hlink');
?>
<a href="<?php echo $url; ?>" target="_blank"><img src="<?php
echo $image['url']; ?>" alt="<?php
echo $image['alt']; ?>" /></a>
<?php
}
$yields = get_field('yields');
$prep = get_field('prep_time');
$cook = get_field('cook_time');
$total = get_field('total_time');
$ingredients = get_field('ingredients');
$instructions = get_field('instructions');
endwhile;
wp_reset_postdata();
endif;
任何帮助将不胜感激!
谢谢!
更新后的single-recipe.php文件-
<?php
/*
* Template Name: Recipes
*/
get_header(); ?>
<div id="primary" class="clearfix">
<div id="content" role="main" class="clearfix">
<header class="blog-entry-header clearfix">
<?php if ( is_sticky() ) : ?>
<hgroup>
<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'azurebasic' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<h3 class="entry-format"><?php _e( 'Featured', 'azurebasic' ); ?></h3>
</hgroup>
<?php else : ?>
<h1 class="blog-entry-title clearfix"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'azurebasic' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
<?php while ( have_posts() ) : the_post(); ?>
</header><!-- .entry-header -->
$args = array(
'post_type' => 'recipes',
'post_status' => 'publish',
'posts_per_page' => '10'
);
$recipes_loop = new WP_Query( $args );
if ( $recipes_loop->have_posts() ) :
while ( $recipes_loop->have_posts() ) : $recipes_loop->the_post();
// Set variables
$title = get_the_title();
$description = get_the_content();
$recipeby = get_field('recipe_by');
$category = get_field('category');
$recipe_description = get_field('recipe_description');
$image = get_field('recipe_image');
if (!empty($image)) {
$url = get_field('hlink');
?>
<a href="<?php echo $url; ?>" target="_blank"><img src="<?php
echo $image['url']; ?>" alt="<?php
echo $image['alt']; ?>" /></a>
<?php
}
$yields = get_field('yields');
$prep = get_field('prep_time');
$cook = get_field('cook_time');
$total = get_field('total_time');
$ingredients = get_field('ingredients');
$instructions = get_field('instructions');
endwhile;
wp_reset_postdata();
endif;
<nav id="nav-single" class="clearfix">
<h4 class="assistive-text"><?php _e( 'Post Navigation', 'azurebasic' ); ?></h4>
<span class="nav-next"><?php next_post_link( '%link', __( '<span class="meta-nav">←</span> Next', 'azurebasic' ) ); ?></span>
<span class="nav-previous"><?php previous_post_link( '%link', __( 'Previous <span class="meta-nav">→</span>', 'azurebasic' ) ); ?></span>
</nav><!-- #nav-single -->
<?php endwhile; // end of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<div class="clear"></div><!-- .clear the floats -->
<?php get_footer(); ?>