• Resolved TonyWilliams

    (@tonywilliams)


    I am trying to create a page of posts and am following the instructions on this link (given to me by alchymyth-thanks for that)
    http://codex.wordpress.org/Page_Templates#A_Page_of_Posts

    However I’m stuck in that the instructions say “The following custom page template file displays the content of the Page, followed by the posts from two specific categories (specified by their category slugs). It is designed to work within a child Theme of the Twenty Thirteen theme. If you are using a different theme, you need to replicate the HTML structure of your own theme within this template.

    Save this to pageofposts.php and then assign the Page of Posts Template to your new Page:”

    Most of the code looks relevant apart from this line:
    <?php twentythirteen_paging_nav(); ?>

    I am using childishly simple child theme but I can’t find a php file with a similar name. So I left the line as it was but changed twentythirteen to childishly_simple_child and added one of my categories in place of the ones shown.

    I uploaded the php file to the server and it shows in the list of templates.

    I created a page called Page of Posts and chose the page of posts template and reviewed it but there was only the page header and nothing else.

    I ran the whole php file through the W3C checker and got this result but no explanation as to what it meant
    Parse Error Lexical error at line 1, column 2. Encountered: “?” (63), after : “<“

    Can someone help?
    Thanks
    Tony
    PS I realise I’ve posted a lot of questions on this theme recently but I have really got to grips with WordPress and the theme basics and the site is developing nicely. It’s only when I want to do something out of the ordinary when I hit a brick wall!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Theme Author richarduk

    (@richarduk)

    I think you’ve bitten off more than you can chew there Tony. The code listed needs a bit of adaptation to make it work/ fit in with the theme. I can have a look at it with a view to including that as a template in an updated version but not tonight. Meantime what about creating a specific category instead of a Page of posts? The only drawback would be if you didn’t want that category showing e.g. in a list of all categories, or if you wanted it shown in a list of all Pages. Apart from that you could link to it from a menu.

    Suspect you might have tried to run the PHP code through the WC3 HTML checker.

    Thread Starter TonyWilliams

    (@tonywilliams)

    Hi Richard, and the WordPress instructions made it sound so easy 🙁 What I’m trying to do is at the top of a page is to have some fixed text which says a few words about the posts that follow. That text would be permanent and the posts would be in post date/time order. The post would all relate to the relevant category. The page of posts concept appeared to be the way to go? I’ll have a look at your alternative suggestions.

    So, back to the drawing board. And I certainly didn’t realise it would be such a big job and certainly didnt expect you to do it tonight!

    Thanks for your help so far.
    Tony

    Theme Author richarduk

    (@richarduk)

    Make copy of page.php

    At the very top put something like this:

    <?php /*
    Template Name: Example multiple posts Page
    */ ?>

    Immediately below
    <?php wp_reset_query( );?>

    paste this

    <?php $loop2 = new WP_Query( 'orderby=title&posts_per_page=5&cat=45' ); ?>
    
    <?php if ( $loop2->have_posts( ) ) :  while ( $loop2->have_posts( ) ) : $loop2->the_post( ); ?>
    
    <div <?php post_class( $childishlysimple_file_name );?>>
    
    <h1 class="page"><?php the_title_attribute( );?></h1>
    
    <div class="entry entry-page">
    
    <?php  the_content( '' ); ?>
    
    </div> <!--Close entry-->
    
    </div><!--Close  post htentry  etc. -->  
    
    <?php endwhile; ?>
    
    <?php else : ?>  
    
    <p> Sorry, no posts were found! </p>
    
    <?php endif; ?> 
    
    <?php wp_reset_query( );?>

    Obviously change around cat. 45 and post_per_page =5 and orderby
    Richard

    Thread Starter TonyWilliams

    (@tonywilliams)

    Thanks Richard, I’m not at home today so I’ll try in the morning. Do I save the new PHP file in the parent folder or the child folder? And would I have to change cat for each category that I have, so basically creating a page template for each category?

    Many, many thanks again and I’ll let you know how I get on!
    Tony

    Theme Author richarduk

    (@richarduk)

    Child folder.

    🙂

    Thread Starter TonyWilliams

    (@tonywilliams)

    Hi Richard. I followed your instructions and here is the php file for the new template:

    [ Moderator note: please wrap code in backticks or use the code button. ]

    <?php /*
    Template Name: Example multiple posts Page
    */ ?>
    <?php get_template_part( 'doctype' ); ?> 
    
    <!--page.php-->
    
    <?php $childishlysimple_file_name='page'; //	Used in     post_class();  ?>
    
    <?php get_header( ); ?>
    
    <?php
    	if (( $childishlysimple_frontend_details['site_layout']=='two_col_cont_right' ) || ( $childishlysimple_frontend_details['site_layout']=='three_col_cont_middle' )  || ( $childishlysimple_frontend_details['site_layout']=='three_col_cont_right' )) get_sidebar( 'left' );
    
    	if ( $childishlysimple_frontend_details['site_layout']=='three_col_cont_right' ) get_sidebar( 'right' );
    ?>
    
    <div class="content content-page">
    
    <div class="header-container">
    	  
    </div><!-- End header-container -->
    
    <?php  if ( have_posts( ) ) : while ( have_posts( ) ) : the_post( ); 	?>
    
    <div <?php post_class( $childishlysimple_file_name );?>>
    
    <h1 class="page"><?php the_title_attribute( );?></h1>
    
    <div class="entry entry-page">
    
    <?php the_content( ); ?>
    
    </div> <!--Close entry-->
    
    <?php
         $childishlysimple_args = array(
       	  'before'           => '<div class="post-links"><p class="post-links">',
     	   'after'            => '</p></div>',
      	  'link_before'      => '<span class="post-links">',
      	  'link_after'       => '</span>',
     	  'next_or_number'   => 'number',
      	  'nextpagelink'     => 'Next page',
      	  'previouspagelink' => 'Previous page',
      	  'pagelink'         => '%',
      	  'more_file'        => '' ,
      	  'echo'             => 1 ); 					
    
     		wp_link_pages( $childishlysimple_args );
    ?>
    
    <?php /* get_template_part( 'comments-pings-trackbacks-allowed' ); */ ?>
    
    <?php edit_post_link( 'Edit this page', '<p class="edit-post">', '</p>' ); ?>
    
    </div><!--Close  post htentry  etc. -->  
    
    <?php endwhile; ?>
    
    <?php comments_template( '', true ); ?>
    
    <?php else : ?>
    
    <?php get_search_form( );   ?> 
    
    <?php endif; ?>
    
    <?php wp_reset_query( );?>
    
    <?php $loop2 = new WP_Query( 'orderby=title&posts_per_page=5&cat=club-galas' ); ?>
    
    <?php if ( $loop2->have_posts( ) ) :  while ( $loop2->have_posts( ) ) : $loop2->the_post( ); ?>
    
    <div <?php post_class( $childishlysimple_file_name );?>>
    
    <h1 class="page"><?php the_title_attribute( );?></h1>
    
    <div class="entry entry-page">
    
    <?php  the_content( '' ); ?>
    
    </div> <!--Close entry-->
    
    </div><!--Close  post htentry  etc. -->  
    
    <?php endwhile; ?>
    
    <?php else : ?>  
    
    <p> Sorry, no posts were found! </p>
    
    <?php endif; ?> 
    
    <?php wp_reset_query( );?>
    
    </div><!--End content-->
    
    <?php
    if (( $childishlysimple_frontend_details['site_layout']=='three_col_cont_left' ) ) get_sidebar( 'left' );
    
    if (( $childishlysimple_frontend_details['site_layout']=='two_col_cont_left' ) || ( $childishlysimple_frontend_details['site_layout']== 'three_col_cont_left' ) || ( $childishlysimple_frontend_details['site_layout']== 'three_col_cont_middle' ) ) get_sidebar( 'right' );
    ?>
    
    <?php get_footer( ); ?>
    
    </body>
    </html>

    I’ve changed cat=45 to cat=club-galas (which is the slug for the category I want to show) and used the template for the page where I want the posts for that category to appear. However, when I view the page it shows ALL the posts for every category, not just for club galas? Any ideas?

    I really appreciate you sticking with me here and feel that this is a useful template to have. I’ve tried a couple of plugins but they don’t appear to work as they should and it has been suggested to me it may be because they clash with files in the theme. But as a complete novice, who is learning quickly, I wouldn’t have any idea about that.

    Again thanks for your help and maybe you could just check my code to make sure I have got it right?
    Tony

    Theme Author richarduk

    (@richarduk)

    Hi Tony, I’ve used your code on my site and it works fine but I used the ID, not the slug. Maybe you’ve got the slug wrong? You could try using the id instead (usually a safer idea in case you change the slug later). I use ‘WP show IDs’ to get the IDs.

    Theme file conflict with plugins – extremely unlikely. Theme functions have to have a unique name for a start. Best way to check is to run the default theme 2013 and see what happens. If you get the same problems it’s the plugins. If all problems disappear it’s my theme (and I’d be interested in knowing what plugins are causing the problems)

    Thread Starter TonyWilliams

    (@tonywilliams)

    Hi Richard, I’ll try that in the morning and post back with the results.
    Thanks again
    Tony

    Thread Starter TonyWilliams

    (@tonywilliams)

    Hi Richard. That worked great using the ID rather than the slug.

    I’ll now create a template for each of my 6 categories.

    If you’re considering adding this as an update (and I think it would be a useful addition) you might want to consider adding the author and date and also give the option of one template but allowing the user to specify which category ID by using code in the Text screen of the editor. There are plugins that do this.

    Anyway I’ve got what I want so far so thanks a million, as ever.
    Regards
    Tony

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Page of posts’ is closed to new replies.