0

I'm playing around with a test site and I've set up a static page as home page.

Now I want to make a menu item called Blog - with url example.com/blog/ - where I'll list the latest articles. I made a custom page template and changed the WP_Query so that it queries a list of 10 latest posts. I then created a page and set the permalink to example.com/blog/.

For the permalinks, I'm using a custom structure /blog/%postname%/ so that my blog posts are like example.com/blog/post-name.

The issue: I would also want that the monthly archive page and the category list page also use that custom page I made instead of their respective template files.

Or another solution I was thinking about is to get the normal archive page to work without using the custom page pointing to example.com/blog.

I'm kinda confused about how to implement the solution.

2 Answers 2

1

When you set up a static page as home page, you can set up also a page for the blog archive. If you do that, you don't need to alter the WP_Query in the blog page template, you only need to work with The loop like in a archive template file. When the page for the blog archive is requested, Wordpress will make the correct query for the blog archive.

To make the monthly/category archive use a different template file than the standard, you can use the template_include filter and the functions is_category() and is_date():

add_filter( 'template_include', 'inlcude_archive_page_template' );
function inlcude_archive_page_template( $template ) {

    if ( is_category() ||  is_date() ) {
         $new_template = locate_template( array( 'the-archive-page-template.php' ) );
         if ( '' != $new_template ) {
             return $new_template ;
         }
    }

    return $template;
}
0

From what I'm understanding, you have two pages set. One page is for the homepage which on your dashboard, under Settings/Reading, you've set as "Front Page". And you have also set the "Posts page" as a page you created titled "Blog".

And so right now, the archive of posts, the url reads "yoursite/blog", correct? If you don't want it to be "blog", you can just re-name your "Blog" page as something else and make sure the slug is what you want? So if you re-name that page as "News", and underneath that page's title while you're editing it, there's an "Edit" option next to the permalink, you can make sure that is now news instead of blog, then the url should read "yoursite/news" instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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