I've registered a new post type called Resources
.
Within the theme root, I've created archive-resources.php
which looks like this:
<?php
/**
* Template Name: Resources
*/
get_header();
while ( have_posts() ) : the_post(); ?>
<div class="resource__wrapper">
<?php the_content(); ?>
</div>
<?php
endwhile;
wp_reset_query();
get_footer(); ?>
Within Resources
, I have a test post called post 1
(which is published). I would've expected the current archive-resources.php
to print out post 1
? But it just prints out "Welcome to WordPress...".
I've also tried the following:
Approach 1:
<?php
/**
* Template Name: Resources Level 1
*/
get_header();
while ( have_posts() ) : the_post();
$args = array(
'post_type' => 'resources',
'posts_per_page' => 10,
'showposts' => 10,
'post_status' => 'publish',
'orderby' => 'publish_date',
'order' => 'DESC'
);
$the_query = new WP_Query($args);
$count = 1;
if ( $the_query->have_posts() ) {
while ($the_query->have_posts() ) {
$the_query->the_post();
get_template_part('templates/widgets/resource-card');
$count++;
if($count > 10) {
$count = 1;
}
}
}
endwhile;
wp_reset_query();
get_footer(); ?>
?>
And resource-card.php
is:
<div id="resource-card" class="col-12 col-sm-6" >
<div class="resourceCard__wrapper">
<h3 class="resourceCard__title"></h3><?php echo get_bloginfo( 'name' ); ?></h3>
<p class="resourceCard__subtitle"> </p>
</div>
</div>
Approach 2:
<?php
/**
* Template Name: Resources Level 1
*/
get_header();
$args = array(
'post_type' => 'resources',
'post_status' => 'publish',
'orderby' => 'publish_date',
'order' => 'DESC'
);
$the_query = new WP_Query( $args );
if($the_query->have_posts()) :
while($the_query->have_posts()) : $the_query->the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content();
endwhile;
endif;
wp_reset_query();
get_footer(); ?>
?>
Where am I going wrong?
Update:
Just noticed under posts
that there's a Hello World
post (which is why it's appearing on my resources page).
So it seems like it isn't looking for posts in the Resources
type ...
Current Approach:
archive-resource.php
<?php
get_header();
while ( have_posts() ) : the_post(); ?>
<div class="resource__wrapper">
<?php the_content(); ?>
</div>
<?php
endwhile;
wp_reset_query();
get_footer(); ?>
?>
How I'm registering the taxonomy:
public function post_types_taxonomies() {
register_post_type(
'resources',
build_post_args(
'resources', 'Resource', 'Resources',
array(
'menu_icon' => 'dashicons-welcome-write-blog',
'menu_position' => 20,
'has_archive' => true,
'public' => true
)
)
);
}
In WP Admin, under Settings > Reading > Posts page is set to Resources
I have a page called Resources (/resources
).
... Still not showing post titled post 1
. I believe index.php
is taking over since the default "welcome to WordPress ..." blog is still being shown.