我一直在尝试获取我的自定义帖子标题,但到目前为止没有运气,我也尝试了引用也无法正常工作。
function create_aop_post_types(){
$args = array(
'label' => 'News',
'public' => true,
'rewrite' => array( 'slug' => 'news' ),
'has_archive' => true,
'menu_position' => null,
'taxonomies' => array('category', 'post_tag'),
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'custom-fields', 'revisions' )
);
register_post_type( 'news', $args );
尝试在 href 中输出"标签"=>"新闻",我尝试使用 permalink the_title();
<div class="feedhead news clearfix"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php echo get_the_title(); ?></a></div>
<div class="newscol-items">
<?php
//Instead do this using a WP Query and loop.
$queryargs = array(
'post_type'=>'news',
'showposts'=>5
);
query_posts($queryargs);
if (have_posts()){
$count = 0;
while (have_posts()) {
the_post();
$count++;
get_template_part('content','news');
}
} else {
get_template_part('content','noposts');
}
wp_reset_query();
?>
</div>
到目前为止,我只在做,但我相信有比我尝试过的更好的方法。
这段代码对我有用,这将获取当前页面帖子类型标签。
<?php $post_type = get_post_type_object( get_post_type( get_the_ID()) );
echo $post_type->labels->singular_name ; ?>
对于标题,the_permalink() 和 the_title() 需要在 while 循环中。然后你也不需要使用 get_the_title()。对于标签,自定义字段更好。请参阅此页面: http://codex.wordpress.org/Custom_Fields
<div class="newscol-items">
<?php
//Instead do this using a WP Query and loop.
$queryargs = array(
'post_type'=>'news',
'showposts'=>5
);
query_posts($queryargs);
if (have_posts()){
$count = 0;
while (have_posts()) { ?>
<div class="feedhead news clearfix"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></div>
<?php the_post();
$count++;
get_template_part('content','news');
}
} else {
get_template_part('content','noposts');
}
wp_reset_query();
?>
</div>
使用高级自定义字段,然后创建一个名为 mycustom_title
的字段,然后执行
<?php the_field("[mycustom_title]"); ?>