- This topic has 5 replies, 2 voices, and was last updated 2 years, 10 months ago by David.
-
AuthorPosts
-
June 2, 2021 at 6:16 am #1807162Dominik
Hi there,
as we have been using custom post types (with custom slugs) quit often in the last months, I was wondering if it is also possible to have a block element content template (like this: https://docs.generatepress.com/article/block-element-content-template/) also for the custom post type overview.
At the moment we are using WP show posts Pro – but it would be nice to use the new functionalities with the block elements.
Thanks and best wishes,
DominikJune 2, 2021 at 6:59 am #1807224DavidStaffCustomer SupportHi there,
if you use the GP theme templates as the basis of your CPT Templates then yes you can use the Content Template in Elements.
For example here in GP’s archive.php:The
generate_do_template_part
within then loop is what Block Element Content Template uses to switch out the template.June 2, 2021 at 7:44 am #1807276DominikHi David,
thanks for the quick response!
What do you mean with “use GP theme templates”? I create a custom post type like/* Referenzen Custom Post Type */ if ( ! function_exists('custom_post_type') ) { // Register Custom Post Type function custom_post_type() { $labels = array( 'name' => _x( 'Referenzen', 'Post Type General Name', 'text_domain' ), 'singular_name' => _x( 'Referenz', 'Post Type Singular Name', 'text_domain' ), 'menu_name' => __( 'Referenzen', 'text_domain' ), 'name_admin_bar' => __( 'Referenzen', 'text_domain' ), 'archives' => __( 'Referenzen Archive', 'text_domain' ), 'attributes' => __( 'Referenzen Attribute', 'text_domain' ), 'parent_item_colon' => __( 'Eltern Referenzen', 'text_domain' ), 'all_items' => __( 'Alle Referenzen', 'text_domain' ), 'add_new_item' => __( 'Neue Referenz', 'text_domain' ), 'add_new' => __( 'Neue Referenz', 'text_domain' ), 'new_item' => __( 'Neue Referenz', 'text_domain' ), 'edit_item' => __( 'Referenz bearbeiten', 'text_domain' ), 'update_item' => __( 'Referenz aktualisieren', 'text_domain' ), 'view_item' => __( 'Zeige Referenz', 'text_domain' ), 'view_items' => __( 'Zeige Referenzen', 'text_domain' ), 'search_items' => __( 'Suche Referenz', 'text_domain' ), 'not_found' => __( 'Nicht gefunden', 'text_domain' ), 'not_found_in_trash' => __( 'Nicht im Papierkorb gefunden', 'text_domain' ), 'featured_image' => __( 'Featured Image', 'text_domain' ), 'set_featured_image' => __( 'Set featured image', 'text_domain' ), 'remove_featured_image' => __( 'Remove featured image', 'text_domain' ), 'use_featured_image' => __( 'Use as featured image', 'text_domain' ), 'insert_into_item' => __( 'Insert into item', 'text_domain' ), 'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ), 'items_list' => __( 'Items list', 'text_domain' ), 'items_list_navigation' => __( 'Items list navigation', 'text_domain' ), 'filter_items_list' => __( 'Filter items list', 'text_domain' ), ); $rewrite = array( 'slug' => 'referenzen', 'with_front' => false, 'pages' => true, 'feeds' => true, ); $args = array( 'label' => __( 'Referenz', 'text_domain' ), 'description' => __( 'Referenzen', 'text_domain' ), 'labels' => $labels, 'show_in_rest' => true, 'supports' => array( 'title', 'editor', 'thumbnail', 'revisions', 'custom-fields', 'page-attributes', 'post-formats' ), 'taxonomies' => array( 'referenzen_taxonomy' ), 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'menu_icon' => 'dashicons-admin-home', 'show_in_admin_bar' => true, 'show_in_nav_menus' => true, 'can_export' => true, 'has_archive' => false, 'exclude_from_search' => false, 'publicly_queryable' => true, 'query_var' => 'post_type_referenz', 'rewrite' => $rewrite, 'capability_type' => 'page', ); register_post_type( 'post_type_referenzen', $args ); } add_action( 'init', 'custom_post_type', 0 ); }
and a content template…but where do I apply the template to?
June 2, 2021 at 9:23 am #1807598DavidStaffCustomer SupportSo that code is registering the Custom Post Type.
Generally you would a PHP Template for the displaying that post type – see here for example on setting up a single templates:https://docs.generatepress.com/article/setting-up-a-simple-custom-post-type/
For the archives to work you would need to:
1. Change this CPT arg
'has_archive' => false,
to'has_archive' => true,
2. Set up an archive PHP with your slug:
You can simply copy the themes
archive.php
and save it as yourarchive-your-slug.php
Then you would be able to display an Archive page that could be rebuilt using the Block Element.
June 4, 2021 at 12:49 am #1809661DominikHi David,
thanks for the great support, as always!
I will give it a try 🙂June 4, 2021 at 3:10 am #1809764DavidStaffCustomer SupportYou’re welcome
-
AuthorPosts
- You must be logged in to reply to this topic.