WordPress: Create a page of Posts

I don’t use menus that simply display all posts from one category as one can do using a custom menu (to be created via the Dashboard > Appearance > Menus). Instead, I use pages with a “custom Template” that displays such post with futher flexibility.

Click to Read More

  1. Create a new “Page Template” (a php file) named “page-of-post.php” and save that one into the root folder of your theme if not yet available: \\<YourSynology>\web\wordpress\wp-content\themes\<YourTheme>\
  2. In this page Template, you should have the code provided at the bottom of this post.
  3. Go to the “Dashboard” > “Pages”, and click “Add New” to create a blank page.
  4. Type a name for your page. This name will be displayed in the menu (Header).
  5. In the “Page Attributes” pane, select “Page of Post” as a “Template” for the new page.
  6. Publish the page
  7. Add now that page to the Custom Menu (via the Dashboard > Appearance > Menus).
  8. Finally, possibly create one “Category Sticky” post which will stay at the bottom of the page and introduce the topic (E.g.: when creating a post, add a category in the “Category Sticky” pane made available via the Plugin “Category Sticky Posts” 0.13 of  Brian Zeligson)

Here is the code of the page Template. Pay attention that I am using the theme ‘twentyeleven’:

[code language=”php”] <?php
Template Name: Page Of Posts

// if you are not using this in a child of Twenty Eleven, you need to replicate the html structure of your own theme.

get_header(); ?>

<div id="primary">
<div id="content" role="main">

$slug = basename(get_permalink());
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
$args= array(
‘category_name’ => $slug, // Change these category SLUGS to suit your use. Ex.: "categ1, categ2"
‘paged’ => $paged

$category = get_category_by_slug($slug);
$name = $slug;
$name = $category->name;
if( have_posts() ) :?>

<?php twentyeleven_content_nav( ‘nav-above’ ); ?>

<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>

<?php get_template_part( ‘content’, get_post_format() ); ?>

<?php endwhile; ?>

<?php twentyeleven_content_nav( ‘nav-below’ ); ?>

<?php else : ?>

<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( ‘Nothing Found in the Category "’.$name.’"’, ‘twentyeleven’ ); ?></h1>
</header><!– .entry-header –>

<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.’, ‘twentyeleven’ ); ?></p>
<?php get_search_form(); ?>
</div><!– .entry-content –>
</article><!– #post-0 –>

<?php endif; ?>

</div><!– #content –>
</div><!– #primary –>

<?php get_sidebar(); ?>
<?php get_footer(); ?>





Leave a Reply

Your email address will not be published. Required fields are marked *