$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>permalinks - Show category name in the post URL only for specific categories|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

permalinks - Show category name in the post URL only for specific categories

matteradmin9PV0评论

Is there a way to show the category name in the URL of a post which is in a specific category? I.e:

I have a site which have a blog and two categories, blog and resources; right now this blog have the setting of only show the post name in the url (blabla/postname) so, all post follow this rule. But now, I have to enable a way for the resources posts show the category name (resources) in the URL, something like this: blabla/resources/postname, and having this two settings living side by side.

Blog must remain blog/postname, Resources should be blog/resources/postname

Thanks!

Is there a way to show the category name in the URL of a post which is in a specific category? I.e:

I have a site which have a blog and two categories, blog and resources; right now this blog have the setting of only show the post name in the url (blabla/postname) so, all post follow this rule. But now, I have to enable a way for the resources posts show the category name (resources) in the URL, something like this: blabla/resources/postname, and having this two settings living side by side.

Blog must remain blog/postname, Resources should be blog/resources/postname

Thanks!

Share Improve this question edited Nov 6, 2019 at 20:43 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Nov 6, 2019 at 20:15 Erick AcevedoErick Acevedo 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

The easiest way would be to create a custom post type with an archive.

<?php
register_post_type('resource',
    array(
        // Enable Core Categories and Tags
        'taxonomies'        => array('category', 'post_tag'),
        // Enable in REST API so it works with the Block Editor
        'show_in_rest'      => true,
        'label' => 'Resources',
        'public'            => true,
        'supports'          => array('title', 'editor', 'excerpt', 'thumbnail', 'revisions'),
        // Archive URL will be example/resources
        'has_archive'       => 'resources',
        // Posts will be at example/resources/postname
        'rewrite'           => array('slug' => 'resources')
    )
);
?>

This will create the post type itself. Then, you can go into the database and change their post_type from post to resource - or you could create PHP code to do this for you if you're not comfortable editing directly in the database.

Post a comment

comment list (0)

  1. No comments so far