-
catherinetoews
Hello,
Within GB 2.0 is there any way to set up a query section on a homepage that pulls pages rather than posts? In this instance, it’s for a client who will be creating new pages about upcoming events and happenings. In this use case pages are preferred for this content rather than posts. Is there any way to label/categorize pages so that all pages of that type moving forward will be the content displayed in a home page query section (rather than it querying all pages / most recent pages)? Essentially I’d like to create a “page category” rather than a post category.
Thank you!
Catherine
-
Hi there,
Yes, you can set the query’s post type to pages, and add Taxonomies parameter, select the term.
https://app.screencast.com/u3O2fwmCuy5fW -
Stefanie
Hi Catherine,
we know each other from Mike’s Community 😉
I came across your question here by chance.If you want to create a taxonomy for pages only, you can do so using this snippet.
Just add it to the functions.php (or via a code plugin):
and change my german translations 😉/************ Register Custom Taxonomy ONLY for pages ******************/ function custom_taxonomy() { $labels = array( 'name' => _x( 'Seiten-Kategorien', 'Taxonomy General Name', 'text_domain' ), 'singular_name' => _x( 'Seiten-Kategorie', 'Taxonomy Singular Name', 'text_domain' ), 'menu_name' => __( 'Kategorien', 'text_domain' ), 'all_items' => __( 'Alle Kategorien', 'text_domain' ), 'parent_item' => __( 'Übergeordnete Kategorie', 'text_domain' ), 'parent_item_colon' => __( 'Übergeordnete Kategorie:', 'text_domain' ), 'new_item_name' => __( 'Neue Kategorie', 'text_domain' ), 'add_new_item' => __( 'Neue Kategorie erstellen', 'text_domain' ), 'edit_item' => __( 'Kategorie bearbeiten', 'text_domain' ), 'update_item' => __( 'Kategorie aktualisieren', 'text_domain' ), 'view_item' => __( 'Kategorie ansehen', 'text_domain' ), 'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ), 'add_or_remove_items' => __( 'Add or remove items', 'text_domain' ), 'choose_from_most_used' => __( 'Choose from the most used', 'text_domain' ), 'popular_items' => __( 'Popular Items', 'text_domain' ), 'search_items' => __( 'Search Items', 'text_domain' ), 'not_found' => __( 'Not Found', 'text_domain' ), 'no_terms' => __( 'No items', 'text_domain' ), 'items_list' => __( 'Items list', 'text_domain' ), 'items_list_navigation' => __( 'Items list navigation', 'text_domain' ), ); $args = array( 'labels' => $labels, 'hierarchical' => true, 'public' => true, 'show_in_rest' => true, /* REST API Support, damit kann z.B GB Query-Loop auf diese Kategorie zugreifen */ 'show_ui' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, ); register_taxonomy( 'pages_category', array( 'page' ), $args ); } add_action( 'init', 'custom_taxonomy', 0 );
This creates a category for pages (just like for posts).
For individual pages you could then assign the category “Show on frontpage” (for example).
and via the Query block you can then only output the pages with this category in the loop.Best regards
Stefanie -
I would recommend using a plugin like ACF to create custom taxonomy, it will be much easier for non-coder users 🙂
-
Stefanie
👍 🙂
-
catherinetoews
Thank you so much for all your help, Ying and Stefanie! Much appreciated!
-
You are welcome 🙂
- You must be logged in to reply to this topic.