I've been trying to get my custom post title but so far no luck, I tried the reference as well couldn't make it to work.
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 );
Trying to output 'label' => 'News' in a href and I tried the_title(); with permalink.
<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>
so far I'm only doing but I'm sure there is a better way of doing it than what I've tried.
Use advanced custom fields then create a field called mycustom_title
, then do
<?php the_field("[mycustom_title]"); ?>
For the title, the_permalink() and the_title() need to be inside the while loop. And then you won't need to use get_the_title() either. For the label, a custom field is better. See this page: 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>
This code is working for me and this will fetch current page post type label.
<?php $post_type = get_post_type_object( get_post_type( get_the_ID()) );
echo $post_type->labels->singular_name ; ?>