WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to set static page as parent of Custom Post Type page (10 posts)

  1. petriedish
    Member
    Posted 1 year ago #

    I'm currently working on an animal rescue site (built with Headway v.3.5.5) that has animals available to sponsor on a monthly basis, as well as animals available to adopt.

    I've created 2 custom post types, one is animals-adopt and one is animals-sponsor, to showcase individual animals.

    I've already figured out how to list the animals available for adoption on my static Adoptions page, and list the animals available to sponsor on the static Sponsorship page.

    Here's where I'm stuck. I want the static Adoptions and Sponsorship pages to be assigned as the parent pages for my respective custom post type single pages.

    Right now, when someone clicks through on one of the animals listed on the static page to open the single CPT page, the breadcrumb navigation on the CPT page shows the Home page as the parent page of the CPT and not one of the respective static pages I've mentioned.

    It shows: Home > Fluffy
    I want it to show: Home > Our Work > Adoptions > Fluffy

    I've tried to figure out a way to set a static page as a parent page for the custom post type in the page editor, but there is no metabox that allows for a static page to be a parent of a custom post type - it only allows another custom post type to be a parent of a CPT page.

    I've tried timstl and ipixelsmediaworks's suggestions from this page http://wordpress.org/support/topic/custom-post-type-parent (adding them to functions.php with the appropriate customizations) to no avail.

    I've spent almost a week researching to try to figure this out. Anything else I've found in wordpress.org forums is either unresolved or closed to new replies.

    Can anyone help me?

  2. Tim Brand
    Member
    Posted 1 year ago #

    You could try using this custom breadcrumbs script vs the one in Headway. This shows a full breadcrumbs and not the abbreviated one.

    http://pastebin.com/bGgZXnwr

  3. David Knight
    Member
    Posted 1 year ago #

    So I may have the answer, or I may be talking rubbish…
    I would make some changes. Give your CPT either a category /custom taxonomy and make sure it has a hierarchy.
    (Ill just use the word category for category/custom taxonomy to stop me having to type it so much!)
    So for Fluffy, he would be in the dog’s category. That would be a child of the category for all animals.
    So your hierarchy would look like so
    All Animals – dogs -- fluffy
    So your breadcrumbs, rather than having to jump through hoops, would just be normal parent/child categories.
    You would need to either edit/make a new category archive page, that has the content from your static pages on it. This would also self update when you add new pets.
    Let me know if that either works or I didn’t explain it very well!

  4. petriedish
    Member
    Posted 1 year ago #

    I posted my same issue in the Headway forums and this is what someone posted that he'd found:

    Does anyone know where I add this code?

    From: http://janina.tumblr.com/post/3588081423/post-parent-different-type

    add_action('admin_menu', function() { remove_meta_box('pageparentdiv', 'chapter', 'normal');});
      add_action('add_meta_boxes', function() { add_meta_box('chapter-parent', 'Part', 'chapter_attributes_meta_box', 'chapter', 'side', 'high');});
    
      function chapter_attributes_meta_box($post) {
        $post_type_object = get_post_type_object($post->post_type);
        if ( $post_type_object->hierarchical ) {
          $pages = wp_dropdown_pages(array('post_type' => 'part', 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('(no parent)'), 'sort_column'=> 'menu_order, post_title', 'echo' => 0));
          if ( ! empty($pages) ) {
            echo $pages;
          } // end empty pages check
        } // end hierarchical check.
      }
  5. petriedish
    Member
    Posted 1 year ago #

    Or, I've just also seen the Posts 2 Posts plugin... does anyone know a step by step way I can use this plugin to achieve my goal?

  6. petriedish
    Member
    Posted 1 year ago #

    Or anyone have luck doing something like what I'm trying to do, using the Types plugin?

    http://wordpress.org/plugins/types/

  7. petriedish
    Member
    Posted 1 year ago #

    I ended up using two plugins to as workarounds solve my issue and get the breadcrumbs and URLs I wanted.

    There was no way to "set" the parent of the CPT page as an existing static page (therefore no way to have the breadcrumbs and URL/permalinks automatically work.)

    So, I used the Breadcrumbs Nav XT for the breadcrumb issues, and I used the Types plugin for the URL issues.

    I recreated every static page in the site's "Our Work" section instead as a CPT page, and used Breadcrumbs Nav XT on those pages only because I could modify the breadcrumb path to appear the way I wanted within that plugin's settings for CPT pages.

    An explanation of how I used the Types plugin to get the permalink URLs I wanted is here.

  8. Maxcom
    Member
    Posted 1 year ago #

    The Striking Premium WordPress Theme has both custom urls and custom breadcrumbs as part of its core settings for its custom portfolio post type. So I believe you can accomplish what you need with that theme.

  9. phillmill
    Member
    Posted 1 year ago #

    I had issues getting the permalinks to link to the actual custom post type (got a 404). My solution was a little bit of rewrite rules: (if anyone ran in to the same thing)

    add_filter('rewrite_rules_array', 'customposttype_rewrites');
    function customposttype_rewrites($rules){
    	$the_parent_page_permalink = substr(get_permalink(70), strlen(home_url('/')));
    	$rules[sprintf('%s(.+?)/(.+?)$', $the_parent_page_permalink)] = 'index.php?customposttype=$matches[2]';
    	return $rules;
    }
  10. zovig
    Member
    Posted 11 months ago #

    Apologies in advance if this question isn't appearing in the right thread, but I can't figure out how to start a new post.

    I've been learning web design and have created a page, which is an html file, 2 css files, and a .js file. Can I add it to my wordpress blog? I don't want it to have the structure of the blog. How would I do that?

    Or do I really need to purchase another domain name just for these little files and just have an external link to it on my blog?

    I hope this makes sense. Can anyone give me any advice?

    Thanks! Mary

Topic Closed

This topic has been closed to new replies.

About this Topic