Community Forums › Forums › Archived Forums › Design Tips and Tricks › Author Pro – Apply Archive Template to Custom Taxonomy
Tagged: archive template, Author Pro, taxonomy
- This topic has 8 replies, 3 voices, and was last updated 9 years, 5 months ago by Elizabeth Kricfalusi.
-
AuthorPosts
-
June 1, 2015 at 8:40 am #154376Elizabeth KricfalusiMember
The Author Pro theme uses a plugin to add a Books custom post type. The plugin includes a number of custom taxonomies but I wanted to add one for Genre. (The theme demo uses "Book Tags" for genres, but I want a specific genre category that doesn't get mixed with other potential tags.)
I've got the taxonomy working, but I can't get it to use the same archive-books.php template that the other taxonomies use for their archives.
I created a copy of one of the existing taxonomy pages and renamed it to taxonomy-book-genres.php, then loaded it into the plugin's template folder, but that didn't work. I then submitted a support ticket and was told that the taxonomy-book-genres.php file should go in the theme folder, not the plugin folder. So I moved it there but it still didn't work.
My thought is that it has to do with the path to the template, since the genres-specific file is in the theme folder and the archive-books.php folder is in the plugins folder. The one line of code in taxonomy-book-genres.php is:
require_once( GENESIS_AUTHOR_PRO_TEMPLATES_DIR . 'archive-books.php' );
I tried changing archive-books.php to the absolute path to the templates folder in plugins, but that didn't work. I wonder if I need to do something to the "GENESIS_AUTHOR_PRO_TEMPLATES_DIR" part instead (or in addition).
Thanks for any help you can provide.
Elizabeth
June 1, 2015 at 8:48 am #154378Genesis DeveloperMemberJune 29, 2015 at 10:12 am #157842Elizabeth KricfalusiMemberThanks to Genesis Developer who replied to me with a suggestion previously, although it seems to have been deleted now.
Unfortunately I got caught up with other jobs and had to put this on the back burner a bit.
I did look back at the email, though, and the suggested plugin was not what I need.
There is already a template for the archive page I want to use. I just can't get it to apply to the new taxonomy I created. I've tried hard-coding the URL to the template and that didn't work. I tried adding the new taxonomy into the construct function in the CPT class file, but that didn't work.
Here is an example of how I want the page to look. It uses the plugin's built-in book-tag taxonomy:
http://jlc.t4lsites.com/book-tag/suspense/
Here is how it looks with my custom book-genre taxonomy:
http://jlc.t4lsites.com/book-genre/suspense/
Again, if anyone can provide any guidance of what I'm doing wrong, that would be greatly appreciated!
Elizabeth
June 29, 2015 at 10:17 am #157843Brad DaltonParticipantHi
Try the WordPress template hierarchy which runs based on file name.
I assume you have copied over the file to your child theme?
Otherwise, you can try template_include
July 5, 2015 at 10:51 am #158416Elizabeth KricfalusiMemberThanks, Brad, for those suggestions and links. Unfortunately, I still haven't been able to get any of them to work.
This is the full contents of taxonomy-books-genre.php:
<?php /** * This file adds the book genre taxonomy archive template to the Genesis Author Pro plugin. * * @author StudioPress * @package Genesis Author Pro * @subpackage Template */ //* Uses the default book post type archive template file require_once( GENESIS_AUTHOR_PRO_TEMPLATES_DIR . 'archive-books.php' );
This is the full content of archive-books.php:
<?php /** * This file adds the book(library) archive template to the Genesis Author Pro plugin. * * @author StudioPress * @package Genesis Author Pro * @subpackage Template */ add_action( 'wp_enqueue_scripts', 'genesis_author_pro_load_default_styles' ); add_action( 'genesis_loop', 'genesis_author_pro_setup_archive_loop', 9 ); //* Add author_pro body class to the head add_filter( 'body_class', 'genesis_author_pro_add_body_class' ); add_filter('post_class' , 'genesis_author_pro_custom_post_class'); genesis();
When I put those files in the Author Pro theme folder, I get these error messages:
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'genesis_author_pro_load_default_styles' not found or invalid function name in /home3/ab19133/public_html/jlc/wp-includes/plugin.php on line 496
Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'genesis_author_pro_add_body_class' not found or invalid function name in /home3/ab19133/public_html/jlc/wp-includes/plugin.php on line 213
Catchable fatal error: Argument 1 passed to genesis_custom_body_class() must be of the type array, null given in /home3/ab19133/public_html/jlc/wp-content/themes/genesis/lib/structure/layout.php on line 61
I also tried removing taxonomy-books-genre.php from the folder (hoping that the built-in hierarchy would kick in), but I get the same messages.
The first two messages seem like the problem is that the template file is calling functions from within the plugin folder so it can't find them. Does that make sense? And if so, how do I solve that? I obviously don't want to copy over all the functions from the plugin folder to the theme folder. Not sure what the third message means.
I tried the include method as well. It didn't give me any errors, but it didn't apply the template either. I'm not sure, however, if I've customized the function correctly for my circumstances. This is the function I've put into functions.php:
function custom_books_archive_page_template( $template ) { if ( is_archive( 'book-genres' ) ) { $new_template = locate_template( array( 'archive-books.php' ) ); if ( '' != $new_template ) { return $new_template ; } } return $template; } add_filter( 'template_include', 'custom_books_archive_page_template', 99 );
I can make this work with the book-tag taxonomy, but it's not ideal because existing tags don't show up in a list like categories do in the admin screen. If there's any chance of an enhancement request for this theme, it would be to add Genre as a category-style taxonomy since it and Author are probably the two main things people are looking for when buying books.
July 5, 2015 at 11:14 am #158420Brad DaltonParticipantThe plugin includes a number of custom taxonomies but I wanted to add one for Genre.
How did you create a custom taxonomy for Genre?
July 5, 2015 at 12:18 pm #158422Brad DaltonParticipantHere's my solution after spending a couple of hours working out and testing a solution
July 5, 2015 at 1:07 pm #158427Elizabeth KricfalusiMemberWow, I wasn't expecting anyone to spend as much time as me on this. I figured actual developers would see my mistakes right off! 🙂
I'm off to check out the response, but I wasn't sure if you were still wondering what I used to create the Genre taxonomy, so I'm putting it here just in case.
/* Register Custom Taxonomies: Book Genres */ function add_custom_taxonomies_book_genres() { // Add new "Book Genres" taxonomy to Books register_taxonomy('book-genres', 'books', array( // Hierarchical taxonomy (like categories) 'hierarchical' => true, // This array of options controls the labels displayed in the WordPress Admin UI 'labels' => array( 'name' => _x( 'Book Genres', 'taxonomy general name', 'author-pro'), 'singular_name' => _x( 'Book Genre', 'taxonomy singular name', 'author-pro' ), 'search_items' => __( 'Search Book Genres', 'author-pro' ), 'all_items' => __( 'All Book Genres', 'author-pro' ), 'edit_item' => __( 'Edit Book Genre', 'author-pro' ), 'update_item' => __( 'Update Book Genre', 'author-pro' ), 'add_new_item' => __( 'Add New Book Genre', 'author-pro' ), 'new_item_name' => __( 'New Book Genre Name', 'author-pro' ), 'menu_name' => __( 'Genres', 'author-pro' ), 'parent_item' => __( 'Parent Book Genre', 'author-pro' ), 'parent_item_colon' => __( 'Parent Book Genre:', 'author-pro' ), ), 'public' => true, 'show_ui' => true, 'query_var' => true, 'show_admin_column' => true, // Control the slugs used for this taxonomy 'rewrite' => array( 'slug' => 'book-genre', // This controls the base slug that will display before each term 'with_front' => false, // Don't display the category base before "/book-genre/" 'hierarchical' => true // This will allow URL's like "/book-genre/suspense/" ), )); } add_action( 'init', 'add_custom_taxonomies_book_genres', 0 ); I'll report back whether I can get your solution to work for me as well. Thanks!
July 5, 2015 at 2:45 pm #158436Elizabeth KricfalusiMemberI decided I was spending way too much time on this, so I decided just to go in and change the plugin function so that book-tag is hierarchical and supports parent categories. It serves my purpose that way and if there's ever a plugin upgrade, it will be an easy enough fix.
Thanks for your help, Brad. Hopefully the solution you came up with can be used by others who run into the same problem.
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.