• Resolved MonkeeWork

    (@monkeework)


    Hello – I’m very much a newbie and have done a few Lynda.com tutorials and just easing my toes into the water as far as WordPress goes. I am attempting to make a page which will list all posts related to a single category.

    I added the following line of code to my custom page template which i am working on and I received an error which i’m hoping someone will help me to resolve.

    Category Definitions/setup
    Name: Profile
    Slug: profile
    Parent: none
    Description: none

    Code added
    if( is_page( 'profile' ) { query_posts( array( 'category_name' => 'profile' ) ); }

    The error message
    Parse error: syntax error, unexpected '{' in /home/maxster/marvel-adventures.com/wp-content/themes/twentyfifteen/custom-showCategoryProfiles.php on line 23

    This is my full code:

    <?php   #custom-showCategoryProfiles.php
    /**
     * Template Name: Custom Show Category Profiles Only
     * Description: Page template shows all posts
     *   belonging to one category only (profiles)
     *   based on page;
     *
     * Template displays all posts to a specific category.
     *
     * SEE: https://www.smashingmagazine.com/2015/06/wordpress-custom-page-templates/
     *
     * @package WordPress
     * @subpackage Twenty_Fifteen
     * @since Twenty Fifteen 1.0
     */
    
    get_header();
    
    echo '<div id="primary" class="content-area">
    	<main id="main" class="site-main" role="main">';
    
    	#get all posts from one category
             #line 23
    	if( is_page( 'profile' ) {
    		query_posts( array( 'category_name' => 'profile' ) );
    	}
            #line 27
    	#Display posts.
    	while ( have_posts() ) : the_post();
    
    		#Include the page content template.
    		get_template_part( 'content', 'page' );
    
    		#If comments are open/have at least one comment,
    		#load up the comment template.
    		if ( comments_open() || get_comments_number() ) :
    			comments_template();
    		endif;
    
    	// End the loop.
    	endwhile;
    
    echo '</main><!-- .site-main -->
    </div><!-- .content-area -->';
    
    get_footer();

    Again, I wish to stress that I am very new to all of this, HTML, CSS, WORDPRESS, Attempting to create a template, etc. I’m very much a newbie in every sense of the word. Thank you to anyone who can help me to resolve my error. I have looked my script over and i don’t see/can’t find any mismatched synstatical errors.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You have an open ( without a corresponding closing ). Change ) { to ) ) {.

    Thread Starter MonkeeWork

    (@monkeework)

    Thank you very much for your excellent help and keen understanding Marious. I was able to resolve my issue very quickly and get the initial result I was hoping for and I learned a lot about working with WordPress in the process.

    Below is the resolved code for anyone whom this might be of benefit too.

    Cheers!

    <?php   #custom-showCategoryProfiles.php
    /**
     * Template Name: Custom Show Category Profiles Only
     * Description: Page template shows all posts
     *   belonging to one category only (profiles)
     *   based on page;
     *
     * Template displays all posts to a specific category.
     *
     * SEE: https://www.smashingmagazine.com/2015/06/wordpress-custom-page-templates/
     *
     * @package WordPress
     * @subpackage Twenty_Fifteen
     * @since Twenty Fifteen 1.0
     */
    
    get_header();
    
    echo '<div id="primary" class="content-area">
    	<main id="main" class="site-main" role="main">';
    
    	#get all posts from one category
    				 #line 23
    	if( is_page( 'profiles' )) {
    		query_posts( array( 'category_name' => 'profile' ) );
    	}
    				#line 27
    	#Display posts.
    	while ( have_posts() ) : the_post();
    
    		#Include the page content template.
    		get_template_part( 'content', 'page' );
    
    		#If comments are open/have at least one comment,
    		#load up the comment template.
    		if ( comments_open() || get_comments_number() ) :
    			comments_template();
    		endif;
    
    	// End the loop.
    	endwhile;
    
    echo '</main><!-- .site-main -->
    </div><!-- .content-area -->';
    
    get_footer();

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display All Posts Related to a Single Category on one page.’ is closed to new replies.