Puzzled to see posts in category are showing on local XAMPP server, however they do not show on the live server. Here is the code to display the category posts.
It is a really simple one pager with links to each of the sections.
front-page.php
holds the template-parts to each of the sections. index.php
decides if there is a static page or a category page and serves the corresponding template. In the folder template-parts
I have category-photos.php
that displays the photos posts.
Like I said, local version runs just fine. On the front-page.php
all the posts from all the sections display fine. In the photos
section the posts also show, on the front-page.php
but also on the individual category page, meaning example.com/photos
does show the photos posts locally just fine.
I also comment each of the php files with <!-- category-photos.php -->
at the top so that I can see in the source if the file is loaded. Locally it shows up in the source, on the live server the category-photos.php
is not even included in the source on the category page, but indeed on the front page.
I use WordPress Duplicator to backup and copy the WordPress installation, the theme files and the database exactly as it is to the live host. The photos posts also show on the front-page.php
of the live page, however not on the category page, example.com/photos
. Must say I tried with theme twentyseventeen
and there the category photos posts display fine of course. What am I doing wrong please?
Have no idea where to start looking for errors. Had a chat with support of the hosting company and they said I might have forgotten to include the category in the menu, but I did include it, .. and they have no clue either apart from that. If it helps I will try and make a public repo of the theme as well as upload to a live dummy server.
index.php
<?php
get_header();
global $wp_query;
$pagename = $wp_query->queried_object->post_name;
// checking if it is a static page or category page
// if the $pagename variable is empty get the category
if(empty($pagename)):
$current_cat = single_cat_title("", false);
// get the template for photos, category-photos.php
get_template_part('template-parts/category', $current_cat);
else:
// else it is a static page
$args = array(
'pagename' => $pagename
);
$query = new WP_Query($args);
if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
// get the template with corresponding page
get_template_part( 'template-parts/page', $pagename );
endwhile;
endif;
wp_reset_postdata();
endif;
get_footer();
?>
front-page.php
<?php
get_header();
// the the template for the photos category, so category-photos.php
get_template_part( 'template-parts/category', 'photos');
get_footer();
?>
category-photos.php
<?php
$args = array(
'category_name' => 'photos',
'post_type' => 'post'
);
// loop over the category photos posts
$query = new WP_Query($args);
echo '<div class="photos-wrap">';
if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();
the_title();
the_content();
endwhile;
endif;
wp_reset_postdata();
?>
</div>
category-photos.php
is not included on the live server on the category page,example.com/photos
but indeed on the front page, where all the photos posts appear fine. So this means the photos posts are there in the db but for some reason are not showing on the category page.index.php
starting withif(empty($pagename)):
then get the current category and thenget_template_part('template-parts/category', $current_cat);
, this pulls in the filecategory-photos.php
and there it loops through the photos posts with a simpleWP_Query
using$args
forphotos
andpost
aspost_type
. This is what is so puzzling to me, I think I am including the template files right and calling the loops OK. Locally the photos posts show on the front page and photos category page fine. So for me this means I am including thecategory-photos
template fine.if(empty($pagename)):
?