0

I have a webpage with posts which belong to specific categories (eg projects). I want to show the archive of a specific category like a page.

Status quo

The site structure is similar to this:

/
/our-work/
/our-work/projects <- here I want to have the archive for projects
/xyz
/...

I use the following settings:

  • category_base = cat
  • permalink_structure = /news/%category%/%postname%/

I can access the projects-archive via example.com/cat/projects.

What I already tried

I tried the following without success:

Removing a page_for_posts and setting it to a newly created page "news".

Including the following code in the .htaccess file before the wordpress section (with and without an [L]: If I use [L,r=301] I get a 301-redirect.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/our-work/projects/$ /cat/projects/
</IfModule>

I think there was a time where it worked somehow, but I can not remember how I did it. (Maybe the page only showed all posts, because it had no other info).

My Questions

  1. Is there a better way to do this? How? (I think about creating a real page and wring a shortcode, that includes/displays all posts in the projects category)
  2. If not - How can I do that?
  3. Is it possible to have the posts of this category in this "subdirectory" like /our-work/projects/acme?
  • Splitting out single category to be handled differently makes me think it might be better served by CPT or taxonomy (depending on rest of your structure). – Rarst Apr 24 '14 at 16:31
  • Would that be different? AFAIK Wordpress CPT are also just posts. Could I use a cpt archive like a page? – Alexander Taubenkorb Apr 24 '14 at 16:46
  • The challenge is not it being posts, it's the elaborate condition you want to single them out (one term out of many). This is probably doable, but my instinct is that changing structure might make more sense. Hard to say confidently without knowing all your information architecture. – Rarst Apr 24 '14 at 16:48
  • Yes, you should use a CPT. @Tyler Carter's answer shows how to add a slug to the permalinks for the CPT. You can create an archive template specific to the post type. In the case of Tyler's code, that archive would be archive-career.php. codex.wordpress.org/File:Template_Hierarchy.png – sagalbot Apr 24 '14 at 21:01
1

You can register a custom post type with a custom slug permalink structure.

$args = array(
   'rewrite' => array( 'slug' => 'our-work/book' ),
);
register_post_type( 'projects', $args );
0

The Answer of Tylor almost worked. I had to set at least the arraykeys has_archive and public to true to use /our-work/projects/

$args = array(
    'label'       => 'projects',
    'description' => 'Projects',
    'rewrite'     => array( 'slug' => 'our-work/projects' ),
    'has_archive' => true, //so I can use /our-work/projects/ (archive)
    'public'      =>'true', //otherwise it included other posts in the archive
    'show_ui'     => true, //to see it in the admin menu
);
register_post_type( 'projects', $args );

I also had to call flush_rewrite_rules() once to update the permalink structure (see https://codex.wordpress.org/Function_Reference/register_post_type#Flushing_Rewrite_on_Activation for details).

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.