WordPress.org

Ready to get started?Download WordPress

Forums

SuperCPT
[resolved] Archive not working (10 posts)

  1. RachelGoldstein71
    Member
    Posted 10 months ago #

    I made a custom template for my custom post type called archive-bc_equipment.php and it is not being called; archive.php is still called. On the other hand, single-bc_equipment.php does work. Any help is appreciated.

    Here is the relevant code.

    <?php
    
    define('MU_PLUGIN_PATH', ABSPATH . 'wp-content/mu-plugins');
    
    define('BC_PREFIX', 'bc_');
    
    function bc_prefix($string='', $safe=true) {
      if (!$safe) {
        return BC_PREFIX . $string;
      } else {
        return (strpos($string, BC_PREFIX) === 0) ? $string : BC_PREFIX . $string;
      }
    }
    
    require(MU_PLUGIN_PATH . '/super-cpt/super-cpt.php');
    
    add_action('after_setup_theme', 'bc_setup_post_types_taxonomies');
    
    function bc_setup_post_types_taxonomies() {
      $equipment = new Super_Custom_Post_Type(bc_prefix('equipment'), 'Equipment', 'Equipment', array('rewrite' => array('slug' => 'equipment-fleet')));
    
      $equipment_cat = new Super_Custom_Taxonomy(bc_prefix('category'), 'Category', 'Categories', 'category', array('rewrite' => array('slug' => 'equipment-category')));
      connect_types_and_taxes($equipment,  array($equipment_cat));
    }

    http://wordpress.org/plugins/super-cpt/

  2. Matthew Boynes
    Member
    Plugin Author

    Posted 10 months ago #

    In your site, what URI are you going to? Note that archive-bc_equipment.php will not render for taxonomy pages for bc_category, it will only render for, in this case, /equipment-fleet/

  3. RachelGoldstein71
    Member
    Posted 10 months ago #

    I am going to /equipment-category/cranes/ which automatically shows archive.php. What do I need to do? Thanks again.

  4. Matthew Boynes
    Member
    Plugin Author

    Posted 10 months ago #

    See the Template Hierarchy, you'll want to use one of the custom taxonomy templates, for instance taxonomy-ec_category.php.

  5. RachelGoldstein71
    Member
    Posted 10 months ago #

    Thank you so much for your patience with me, I know I should be able to figure this out on my own. My custom taxonomy probably make more sense to me if I were the person who built the site and wrote the taxonomies myself, but someone else did and I'm afraid to change them now.

    Anyway, If I have 4 categories, an example of one of them is cranes, and I want one archive or category template that will work for each of the 4 categories, then based on the code I pasted above, what should I name that category or archive template? The link being called is /equipment-category/cranes/. I've tried naming the template about 5-10 different things, but it keeps calling archive.php.

    It did work when you said to go to equipment-fleet/, but it doesn't work for the categories within that, and doesn't work for equipment-category.

    Thanks again.
    Rachel

  6. RachelGoldstein71
    Member
    Posted 10 months ago #

    Ah! Got it with taxonomy.php.
    Thanks.

  7. Matthew Boynes
    Member
    Plugin Author

    Posted 10 months ago #

    Just to confirm, you tried taxonomy-bc_category.php? (note that I had a typo above and wrote ec_).

  8. RachelGoldstein71
    Member
    Posted 10 months ago #

    Actually there was no taxonomy template at all so I just used taxonomy.php and it defaults to that without anything extra.

  9. RachelGoldstein71
    Member
    Posted 10 months ago #

    One other thing, when I am in the single-bc_equipment.php template, I want to be able to have a link back to the parent category. For example, if viewing equipment in the cranes cateogry, then a "Back to Cranes" link. I can see that with custom post types, this doesn't work in the usual way, is that correct?

  10. Matthew Boynes
    Member
    Plugin Author

    Posted 10 months ago #

    Yes, true, though be careful -- if you ever add another taxonomy, that too will look to taxonomy.php. Just something to keep in the back of your mind.

    Personally, I make taxonomy.php a highly generic file (not unlike archive.php) and all taxonomy-specific archives get their own file.

    Glad you got it all sorted out!

Reply

You must log in to post.

About this Plugin

About this Topic