0

I have a "normal" WordPress install. Blogposts are displayed on the homepage an there are a few pages.

Now I want to display the posts of a specific category on a page, so that I can add some additional info above the post list.

First, I created the page in the WP Admin (ex. "Awesome Posts", page ID: 31)

Then I created a new page template, named it after the page id (page-31.php) and in there I created another WP_Query to get the posts of some category.

<?php
  // The default "page" content
  while ( have_posts() ) : the_post();
    get_template_part( 'content', 'single' );
  endwhile;

  // Custom category query
  $awesome= new WP_Query( 'category_name=awesome' );
  if ( $awesome->have_posts() ) :
    while ( $awesome->have_posts() ) : $awesome->the_post();
      get_template_part( 'content', 'awesome' );
    endwhile;
  endif;
?>

This works as expected and I get a list of awesome posts on my page. The URL of this page is /awesome. My permalink structure is /%postname%/ so that normal posts on the homepage get a URL like /postname. Now I would like to have the posts on this specific page link to /awesome/posttitle and this is where I get stuck.

Do you now of a way to achive this?

  • 1
    I do not think that will be straight-way possible. What you are trying to do is more like a category page. Why not create a category called "awesome" and have category specific page for this? On the top of the posts listing you can query for the content of a specific page as you want to display. In this way you can maintain the urls as you have referred. – Chittaranjan Feb 17 '15 at 9:53
  • You are right. For the case I mentioned the category page would be the easiest solution. I was thinking about "WordPress as a CMS" where you have mostly pages and on some of these pages you could have different news sections. Or maybe some custom post types. – Florian Grell Feb 18 '15 at 8:10
0

The only way I can see this working is by setting a couple of redirect rules in your .htaccess file. You'd have to manually redirect all your posts (that you want with that permalink structure) and prepend the /awesome URL part in front.

Other than the aforementioned solution, which is a hack more than anything, I'm afraid that what you're looking for is not possible. As @Florian Grell said above, this is a behaviour best suited for categories rather than pages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.