我是一个开发wp主题的新手,在展示我的cpt时遇到了困难。
我在函数中添加了新的cpt。php文件:
// Creates Testimonials Custom Post Type
function testimonials_init() {
$args = array(
\'label\' => \'Testimonials\',
\'public\' => true,
\'show_ui\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'rewrite\' => array(\'slug\' => \'testimonials\'),
\'query_var\' => true,
\'menu_icon\' => \'dashicons-format-quote\',
\'supports\' => array(
\'title\',
\'editor\',
\'excerpt\',
\'trackbacks\',
\'custom-fields\',
\'comments\',
\'revisions\',
\'thumbnail\',
\'author\',
\'page-attributes\',)
);
register_post_type( \'testimonials\', $args );
}
add_action( \'init\', \'testimonials_init\' );
我创建了一个新的页面模板,并添加了以下代码:
<?php
/*
* Template Name: Testimonials
*/
?>
<?php get_header(); ?>
<div class="container">
<div class="content-page">
<h1><?php wp_title(); ?></h1>
<title><?php wp_title(); ?></title>
<?php
$query = new WP_Query( array(\'post_type\' => \'testimonials\', \'posts_per_page\' => 5 ) );
while ( $query->have_posts() ) : $query->the_post(); ?>
<?php endwhile; ?>
</div>
</div>
<?php
$args = array( \'post_type\' => \'testimonials\', \'posts_per_page\' => 10 );
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="entry-content">
<?php the_content(); ?>
</div>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( \'Sorry, no posts matched your criteria.\' ); ?></p>
<?php endif; ?>
<?php get_footer(); ?>
我希望我的页面在前端显示所有推荐信,但我无法做到这一点,因此出现以下错误:
Parse error: syntax error, unexpected \'else\' (T_ELSE)
谢谢大家!!!