Create custom post type in wordpress custom theme

On your WordPress website, post types are used to help distinguish between different content types in WordPress. Posts and pages are both post types but are made to serve different purposes.

Download & install custom post type maker plugin. Create custom post type.

index.php / page.php

<?php

$args = [
'post_type' => 'news',
'post_status' => 'publish'
];

// The Query.
$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) : while( $the_query->have_posts() ) : $the_query->the_post(); ?>

<h1>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h1>

<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'thumbnail' ); ?>
</a>

<p><?php the_excerpt(); ?></p>

<?php endwhile; endif;

?>

Leave a Reply