【发布时间】:2017-05-01 20:33:34
【问题描述】:
我尝试使用 wordpress 中的简码方式自定义我自己的帖子。我想根据帖子的类别显示帖子。
<?php
function sample_post($atts) {
extract(shortcode_atts(array(
'category_name' => 'uncategorized'
), $atts));
$args = array('category_name' => $category_name);
query_posts($args);
if (have_posts()) : while (have_posts()) : the_post(); ?>
<label><?php the_title(); ?></label>
<?php
endwhile;
endif;
}
add_shortcode('sample_post', 'sample_post');
?>
代码很好,我的模板名称中有一个文件content-page.php
这是我的内容页面的代码
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'unite' ),
'after' => '</div>',
) );
edit_post_link( __( 'Edit', 'foodgrower' ), '<span class="edit-link">', '</span>' );
?>
</div><!-- .entry-content -->
</article><!-- #post-## -->
我不知道我是否错过了有关设置或查询的内容。这是我真正想要展示的。我只想显示<label><?php the_title(); ?></label>(帖子的标题),但现在显示的是content-page.php。我也不明白为什么它会出现在我的页面中。我没有调用 content-page.php 来显示在我的页面中。
【问题讨论】: