WordPress.org

Forums

How to get category slug in url (8 posts)

  1. Soron
    Member
    Posted 1 year ago #

    Is there a way to add the category slug in the url of a page or post?

    For example:
    I have a post/page with a category "business".

    I do want to get:
    http://www.mydomain/business/postname

    But i get
    http://www.mydomain/postname

    In the permalinks setup i choose "costum structure" and added "/%category%/%postname%/" but that doesn't seem to work. :(

    Thank you for your time!

  2. Media X
    Member
    Posted 1 year ago #


  3. Soron
    Member
    Posted 1 year ago #

    Got his in my mail:
    "Media X wrote:

    Did you enter anything in the Category base field? Check this
    "

    Check what? :)

  4. Rod Whiteley
    Member
    Posted 1 year ago #

    I tried the custom structure /%category%/%postname%/ and it worked for me. I have a post with the title Elephant in the category DH, and its URL is now like:

    http://example.com/dh/elephant/

    The category base is not useful for this. It is used to change the URL for category archives. For example, in my site DH is a Source, so I have changed the category base to source. This means that the category archive for DH now has the URL:

    http://example.com/source/dh/

  5. Soron
    Member
    Posted 1 year ago #

    Yes, It works for posts, but not for pages, which I added categorys for with this code:

    //Pages Tags & Category Meta boxes
    function add_pages_meta_boxes() {
    add_meta_box(   'tagsdiv-post_tag', __('Page Tags'), 'post_tags_meta_box', 'page', 'side', 'low');
    add_meta_box(   'categorydiv', __('Categories'), 'post_categories_meta_box', 'page', 'normal', 'core');
    }
    add_action('add_meta_boxes', 'add_pages_meta_boxes');
    
    add_action('init','attach_category_to_page');
    function attach_category_to_page() {
        register_taxonomy_for_object_type('category','page');
    }
    //end
  6. Soron
    Member
    Posted 1 year ago #

    It seems you can make a hierarchy in the page attributes. By selecting a parentpage I can get the url i want.

    Thus:
    http://www.mydomain.com/parentpage/page

    But then I need a landingpage for each parentpage instead of an archive like the categories.

    Hmm.. will see if this works out.

  7. Media X
    Member
    Posted 1 year ago #

    Soron, after i posted that about Category base i realized it has nothing to do with your problem so i removed my comment. You received the notification though :P

  8. automaton
    Member
    Posted 9 months ago #

    You could make a custom template for the parent page and generatic an automatic list of child pages there.
    This would work well for relatively small amounts of content (ie not hundreds and hundreds of posts)

Topic Closed

This topic has been closed to new replies.

About this Topic