Using shortcode to display a post category on a page
-
I am trying to add a couple of pages to a client’s website. He wanted his visitors to be able to click on a menu link and be taken to a page that displays all the posts from the category for that menu item… like menu item “Album Reviews” would take them to all of his music album reviews.
I did this successfully for 3 pages already. Now I’m trying to add 2 more, and I can’t get them to work.
The method I’m using (wish I could find the support page for it again) says to use the page.php page and create page-category-slug.php, with custom code added to display the category posts, like so:
<?php /** * The template for displaying all pages. * * This is the template that displays all pages by default. * Please note that this is the WordPress construct of pages * and that other 'pages' on your WordPress site will use a * different template. * * @package fortunato */ get_header(); ?> <div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content', 'page' ); ?> <?php echo do_shortcode('[catlist name=album-reviews excerpt=yes posts_morelink="Read more..."]'); ?> <?php // If comments are open or we have at least one comment, load up the comment template if ( comments_open() || get_comments_number() ) : comments_template(); endif; ?> <?php endwhile; // end of the loop. ?> </main><!-- #main --> </div><!-- #primary --> <?php get_sidebar(); ?> <?php get_footer(); ?>
Is there something else I have to do beside creating the page? Do I need to edit something elsewhere to make the pages work? Any help would be much appreciated.
- The topic ‘Using shortcode to display a post category on a page’ is closed to new replies.