skip to Main Content

Would something like this work? Am I missing anything?

function page_attributes_for_posts() {
    register_post_type('job-bank-posts',
        $args = array(
            'hierarchical' => true,
            'supports' => 'page-attributes'
        );
    );
};
add_action ('init', 'page_attributes_for_posts');

This is one of the sources I used:
https://developer.wordpress.org/reference/functions/register_post_type/

3

Answers


  1. Maybe a complete example could be helpful:

     function create_job_bank_posts() {
      register_post_type( 'book',
        array(
          'labels' => array(
            'name' => __( 'Job Bank Posts' ),
            'singular_name' => __( 'Job Bank Post' ),
            'add_new' => _x('Add Job Bank Post', 'Job Bank Post'),
            'add_new_item' => __('Add Job Bank Post'),
            'edit_item' => __('Edit Job Bank Post'),
            'new_item' => __('New Job Bank Post'),
            'view_item' => __('View Job Bank Post'),
            'search_items' => __('Search Job Bank Post'),
            'not_found_in_trash' => __('Not found in trash'),
          ),
          'public' => true,
          'menu_icon' => 'your-dashicon',
          'rewrite' => array( 'slug' => 'job_bank_posts', 'with_front' => true ),
          'menu_position' => 3,
          'hierarchical' => true,
          'supports' => array(
                    'title',
                    'page-attributes',
                    'thumbnail',
                    'editor',
                    'excerpt',
                    'author',
                    'comments',
                    'custom-fields',
                ),
        )
      );
    }
    add_action( 'init', 'create_job_bank_posts' );
    
    Login or Signup to reply.
  2. Forgive me if this isn’t quite what you are after. OK, I managed to achieve something like this purely using WordPress’s built-in Permalink Settings. The other issue with this quick method is that you will no longer have the use of categories. But its works well for us.

    1. go to wp-admin/options-permalink.php

    2. Select: Custom Structure

    3. you’ll want a structure like the following: /about/%category%/%postname%/

    4. The category you choose for each post will become the parent for all posts under that category.

    5. I then create an extra file in my template called ‘periodic-category.php’ :

    `<?php if (!defined('ABSPATH')) exit;
    /*
    Template Name: Periodic category
    */
    
    get_header();
    
    echo $app->templates()->get('pages/category')->render([
        'post' => $post,
        'parts' => [
            'breadcrumbs' => $app->templates()->get('layout/breadcrumbs')->render(),
            'left_menu' => $app->templates()->get('layout/menu-left')->render(['tax' => 'periodic', 'post' => $post])
        ]
    ]);
    
    get_footer();
    `
    1. You then want to create a page for each category and select periodic-category.php as the template in the post editor.

    2. When ever you create a new post and select a category, it will be listed when you visit the category page.

    The answer above provides you with the opportunity to add multiple parents pages for posts. If you simply want one parent page, then it is as follows:

    1. From the Dashboard, choose Pages→Add New. …
    2. Type a name for the page in the text box toward the top of the page. …
    3. Leave the text box blank. …
    4. Click the Publish button. …
    5. Choose Settings→Reading. …
    6. From the Posts Page drop-down list, choose the page you just created. Done

    I’m happy to share files etc if that is permitted here. Please forgive me as i am new. So happy to learn from others.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search