我可以用另一双眼睛看这个。。。我上次创建Wordpress主题已经有一段时间了。我搞不清楚我到底做错了什么。
我创建了一个自定义帖子类型(日志),并在自定义模板上设置了一个循环,我在主页上设置了该模板<然后我有一个日记账。单个帖子类型的php模板<在我的主页模板中,期刊CPT帖子显示得很好,url/permalink在检查时看起来是正确的。然而,当我点击其中任何一个(目前我有三个)时,它们都会显示最新帖子的内容。url栏中的url/permalink也显示正确,但内容错误。下面是一些代码:这是主页模板上的循环:
<div class="post-slider">
<?php $args = array(\'post_type\' => \'journal\',
\'posts_per_page\' => -1,
\'post_status\' => \'publish\',
\'orderby\' => \'date\',
\'order\' => \'DESC\');
$loop = new WP_Query($args);
if ( $loop->have_posts() ) :
while ( $loop->have_posts() ) :
$loop->the_post(); ?>
<div class="post-card">
<div class="post-card-inner">
<?php if ( has_post_thumbnail() ) {the_post_thumbnail();} ?>
<a href="<?php the_permalink(); ?>"
rel="bookmark"
title="Permanent Link to <?php the_title_attribute(); ?>">
<p><?php the_title(); ?></p>
</a>
</div>
</div>
<?php
// End the loop.
endwhile;
else:
?>
<h1>No posts here!</h1>
<?php endif;
wp_reset_postdata(); ?>
</div>
这是来自单个日志的循环。php:
<?php $args = array(\'post_type\' => \'journal\',
\'showposts\' => 1,
\'post_status\' => \'publish\',
\'orderby\' => \'date\',
\'order\' => \'DESC\');
$loop = new WP_Query($args);
if ( $loop->have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php get_template_part( \'content\', get_post_format() ); ?>
<!--- Add authorname taxonomy -->
<?php the_terms( $post->ID, \'authorname\', \'Author: \', \', \', \' \' ); ?>
<hr/>
<nav class="nav-single">
<h3 class="assistive-text"><?php _e( \'Post navigation\', \'twentytwelve\' ); ?></h3>
<span class="nav-previous"><?php previous_post_link( \'%link\', \'<span class="meta-nav">\' . _x( \'←\', \'Previous post link\', \'twentytwelve\' ) . \'</span> %title\' ); ?></span>
<span class="nav-next"><?php next_post_link( \'%link\', \'%title <span class="meta-nav">\' . _x( \'→\', \'Next post link\', \'twentytwelve\' ) . \'</span>\' ); ?></span>
</nav><!-- .nav-single -->
<?php comments_template( \'\', true ); ?>
<?php endwhile; endif; wp_reset_postdata();// end of the loop. ?>
这是自定义帖子类型:
/*
** Journal Entry
**
*/
function journal_entry() {
// creating (registering) the custom type
register_post_type( \'journal\',
array(
\'labels\' => array(
\'name\' => __( \'Journal Entry\' ),
\'singular_name\' => __( \'Journal Entry\' ),
\'add_new\' => __( \'Add New Journal Entry\' ),
\'add_new_item\' => __( \'Add New Journal Entry\' ),
\'edit_item\' => __( \'Edit Journal Entry\' ),
\'new_item\' => __( \'Add New Journal Entry\' ),
\'view_item\' => __( \'View Journal Entry\' ),
\'search_items\' => __( \'Search Journal Entry\' ),
\'not_found\' => __( \'No Journal Entry found\' ),
\'not_found_in_trash\' => __( \'No Journal Entry found in trash\' ),
\'menu_name\' => _x( \'Journal Entry\', \'journal\' ),
),
//\'taxonomies\' => array(\'category\'),
\'public\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'supports\' => array( \'title\', \'editor\', \'thumbnail\', \'custom-fields\' ),
\'capability_type\' => \'post\',
\'rewrite\' => array("slug" => "journal"), // Permalinks format
\'has_archive\' => true,
\'query_var\' => true,
\'menu_position\' => 5,
\'menu_icon\' => \'dashicons-book-alt\', /* the icon for the custom post type menu */
//\'register_meta_box_cb\' => \'add_team_members_metaboxes\'
//\'yarpp_support\' => true
)
); /* end of register post type */
/* this adds your post categories to your custom post type */
//register_taxonomy_for_object_type( \'category\', \'stories\' );
/* this adds your post tags to your custom post type */
//register_taxonomy_for_object_type( \'post_tag\', \'custom_post_faq\' );
}
add_action( \'init\', \'journal_entry\');
function journal_taxonomy() {
register_taxonomy(
\'journal_categories\', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
\'journal\', //post type name
array(
\'hierarchical\' => true,
\'label\' => \'Custom Categories\', //Display name
\'query_var\' => true,
\'rewrite\' => array(
\'slug\' => \'journal-categories\', // This controls the base slug that will display before each term
\'with_front\' => false // Don\'t display the category base before
)
)
);
}
add_action( \'init\', \'journal_taxonomy\');