I made some Custom Post Types, filled them up with some posts, added the template tags to the templates.
The problem now is that whenever I click the 'Read More' button on a custom post type (the_permalink()), it doesn't show the singlepage. It shows the homepage.
I've created a single.php file and a single-smoelenboek.php file, it should go to 1 of those 2.
I've also flushed by clicking the 'Save' button in settings -> permalinks.
Permalinks are on Post Name right now, I them around a bit, but it didn't matter.
The Custom Post Type
function smoelenboek() {
$labels = array(
'name' => _x( 'Smoelenboek Sectie', 'post type general name', 'your-plugin-textdomain' ),
'singular_name' => _x( 'Smoelenboek Sectie', 'post type singular name', 'your-plugin-textdomain' ),
'menu_name' => _x( 'Smoelenboek Sectie', 'admin menu', 'your-plugin-textdomain' ),
'name_admin_bar' => _x( 'Smoelenboek Sectie', 'add new on admin bar', 'your-plugin-textdomain' ),
'add_new' => _x( 'Smoelenboek item toevoegen', 'content', 'your-plugin-textdomain' ),
'add_new_item' => __( 'Voeg een nieuwe Smoelenboek item toe', 'your-plugin-textdomain' ),
'new_item' => __( 'Nieuwe Smoelenboek item', 'your-plugin-textdomain' ),
'edit_item' => __( 'Bewerk Smoelenboek item', 'your-plugin-textdomain' ),
'view_item' => __( 'Bekijk Smoelenboek item', 'your-plugin-textdomain' ),
'all_items' => __( 'Alle Smoelenboek items', 'your-plugin-textdomain' ),
'search_items' => __( 'Zoek Smoelenboek items', 'your-plugin-textdomain' ),
'parent_item_colon' => __( 'Hoofd Smoelenboek items', 'your-plugin-textdomain' ),
'not_found' => __( 'Geen Smoelenboek items gevonden', 'your-plugin-textdomain' ),
'not_found_in_trash' => __( 'Geen Smoelenboek items gevonden in prullenbak', 'your-plugin-textdomain' )
);
$args = array(
'label' => __('smoelenboek'),
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => false,
'query_var' => true,
'rewrite' => array( 'slug' => 'smoelenboek' ),
'capability_type' => 'post',
'has_archive' => false,
'hierarchical' => true,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields', 'revisions','post-formats' )
);
register_post_type( 'smoelenboek', $args );
}
add_action( 'admin_init', 'smoelenboek' );
The Section
<?php $options = get_option( 'custom_voorpagina_panel_smoelenboek' ); ?>
<section id="smoelenboek">
<div class="container persoon-wrapper">
<h1> <?php echo $options['smoelenboek-titel']; ?> </h1>
<h3> <?php echo $options['smoelenboek-sub-titel']; ?> </h3>
<?php
$loop = new WP_Query(
array(
'post_type' => 'smoelenboek',
'posts_per_page' => 4
)
);
while($loop->have_posts()):
$loop->the_post();
$thumbnail_url = wp_get_attachment_url(get_post_thumbnail_id());
?>
<div class="persoon">
<?php
$image = get_field('afbeelding');
if( !empty($image) ):
// thumbnail
$size = 'products_thumb';
$thumb = $image['sizes'][ $size ];
$width = $image['sizes'][ $size . '-width' ];
$height = $image['sizes'][ $size . '-height' ];
?>
<img src="<?php echo $thumb; ?>" width="<?php echo $width; ?>" height="<?php echo $height; ?>">
<div class="wrapper">
<h3> <?php the_title(); ?> </h3>
<a href="<?php the_permalink() ?>"> <?php the_field('button_tekst') ?></a>
</div>
</div>
<?php
endif;
endwhile;
?>
</div>
<div class="meer-personen container">
<a href="/"> <?php echo $options['smoelenboek-bekijk-meer']; ?> </a>
</div>
</section>
Conclusion: Created custom post type, single page of custom post type not working. It would be nice if someone could help me with this.
EDIT: also single-smoelenboek.php is not working.
EDIT 2: /hello-world works. Picks up the single.php perfectly fine.
Thanks, Dan.
smoelenboek
init
.admin-init
only fires on admin screens.