WordPress.org

Forums

[resolved] Page Template Showing Page Content Followed by Specific Post Categories (5 posts)

  1. LClark52
    Member
    Posted 1 year ago #

    Hi,
    I'm using the Twenty Ten theme. I'm trying to create a page template which shows the content of the page followed by posts in specific categories. I consulted the Codex and came up with the following code:

    <?php
    /*
    Template Name: Page Of Specific Post Categories
    */
    
    /* This is for a child theme of Twenty Ten. */
    
    get_header(); ?>
    
    		<div id="container-right" class="no-title">
    			<div id="content" role="main">
    
    			<?php
    			/* The loop: the_post retrieves the content
    			* of the new Page list the posts,
    			*/
    			if ( have_posts() ) :
    				while ( have_posts() ) : the_post();
    
    				// Display content of page
    				get_template_part( 'loop', 'page' );
    				wp_reset_postdata();
    
    				endwhile;
    			endif;
    
    			$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    			$args = array(
    				// Change these category SLUGS to suit your use.
    				'category_name' => 'music, videos, other',
    				'paged' => $paged
    			);
    
    			$list_of_posts = new WP_Query( $args );
    			?>
    			<?php if ( $list_of_posts->have_posts() ) : ?>
    				<?php /* The loop */ ?>
    				<?php while ( $list_of_posts->have_posts() ) : $list_of_posts->the_post(); ?>
    					<?php // Display content of posts ?>
    					<?php get_template_part( 'loop', 'single' ); ?>
    				<?php endwhile; ?>
    
    			</div><!-- #content -->
    		</div><!-- #container-right -->
    
    <?php get_footer(); ?>

    However, when I run the template, I get the error message "syntax error, unexpected $end on line 47". I have checked my code several times and I can not figure out my mistake. I would greatly appreciate your help.

    Many thanks in advance.

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    Are you using a child theme?

  3. LClark52
    Member
    Posted 1 year ago #

    Hi esmi,

    Thank you for your response.

    Yes, I'm using a child theme.

  4. LClark52
    Member
    Posted 1 year ago #

    I also added the following code after <?php endwhile; ?> to show an error
    if there are no posts.

    <?php else : ?>
    				<?php /* If there are no posts to display, such as an empty archive page */ ?>
    				<?php if ( ! have_posts() ) : ?>
    					<div id="post-0" class="post error404 not-found">
    						<h1 class="entry-title"><?php _e( 'Not Found', 'twentyten' ); ?></h1>
    						<div class="entry-content">
    							<p><?php _e( 'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.', 'twentyten' ); ?></p>
    							<?php get_search_form(); ?>
    					         </div><!-- .entry-content -->
    				         </div><!-- #post-0 -->
    <?php endif; ?>

    However, I still get the error message.

  5. LClark52
    Member
    Posted 1 year ago #

    Finally figured it out.

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Topic