0
votes

So I am setting up a custom WordPress theme using two custom post types Articles and News. Each one is also using a custom single-post.php page single-articles.php and single-news.php. But after pulling the article posts on the main page and inserting their permalink into a 'Read more' link when I click on one of the article's links it takes me to their permalink URL but instead of displaying the article post it displays the News post content. Both single-articles.php and single-news.php are in the themes folder, not in a subfolder.

Here is an example of how I'm setting up the custom posts...

add_action( 'init', 'articles_custom_postypes' );
function articles_custom_postypes() {
$args = array (
'label' => $labels,
'public' => true,
'menu_position' => 100,
'menu_icon' => 'dashicons-format-aside',
'label' => 'Articles',
'has_archive' => false,
'supports' => array( 'title','editor', 'thumbnail'),

);

register_post_type( 'articles', $args);

}

On the custom single post pages I am just calling the_title(), the_content, etc. Should I be using a while loop or something? Any advice would be awesome. Thanks!

1

1 Answers

1
votes

For this you have to have two files in your theme folder. One is single-articles.php and other is content-articles.php. If the files are created add the following code to single-articles.php.

<?php
    while ( have_posts() ) : the_post();
        get_template_part( 'content-articles', get_post_format() );
    endwhile;
?>

Also add the following to content-articles.php.

<?php
    the_title();
    the_content();
?>