Come creare un modello personalizzato per una tassonomia personalizzata?
3 risposta
- voti
-
- 2012-08-15
Modelli
Consultail Template Hiearchy per un'analisipiù dettagliata di come WordPress sceglieilmodello.
/p>
Per un terminetassonomia
slug
('monitora'iltuoesempio)nellatassonomiataxonomy
(ades. 'prodotti') WordPress prova a utilizzarei seguentimodelli (in questo ordine)taxonomy-{taxonomy}-{slug}.php taxonomy-{taxonomy}.php taxonomy.php archive.php index.php
Per lapagina deitermini dellatassonomia deituoi "monitor",WordPress utilizzerà
taxonomy-products-monitors.php
se esiste. In caso contrario,per quellatassonomia verràeseguitoilfallback a
taxonomy-products.php
e così via.
Permalink
Il seguente URL devepuntare allapagina deiprodotti "monitor":
www.example.com?products=monitors
Hai anche specificato una riscrittura dell'URL,quindi supponendo che le regole di riscrittura siano state cancellatee non ci siano conflitti,dovrebbefunzionare anche quanto segue
www.example.com/products-category/monitors
Templates
See the Template Hiearchy for a more detailed break down of how WordPress chooses the template.
For a taxonomy term
slug
('monitors' your example) in the taxonomytaxonomy
(e.g. 'products') WordPress will try to use the following templates (in this order)taxonomy-{taxonomy}-{slug}.php taxonomy-{taxonomy}.php taxonomy.php archive.php index.php
For your 'monitors' taxonomy term page, WordPress will use
taxonomy-products-monitors.php
if it exists. If it doesn't, then for that taxonomy it will fallback to
taxonomy-products.php
and so on.
Permalinks
The following url should point to the 'monitors' products page:
www.example.com?products=monitors
You have also specified an url rewrite, so assuming the rewrite rules have been flushed and there isn't a clash, the following should also work
www.example.com/products-category/monitors
-
Okgrazie.Ora ho unmodello `taxonomy-products-monitors.php`,sono andato alla sezionepermalinkse hofatto clic su Salva (che lo svuotagiusto?) Quindi sono andato allapagina` http://www.neurosignsurgical.com/v2/products-categoria/monitor`mamostra ancora un 404. Davveronon capiscoperché!Ok Thanks. I now have a template `taxonomy-products-monitors.php`, went to the permalinks section and clicked save (that flushes it right?) then went to the page `http://www.neurosignsurgical.com/v2/products-category/monitors` but it still shows a 404. Really don't understand why!
- 0
- 2012-08-15
- Rob
-
Questo lo svuota,sì.Tienipresente chei termini coni postnowprobabilmentemostreranno un "nullatrovato".Seilprimo collegamentofunziona,allora è unproblema dipermalink.Dovresti [usare questoplug-in] (http://wordpress.org/extend/plugins/monkeyman-rewrite-analyzer/)per diagnosticare.Unmodellonon avràeffetto su un 404.That does flush it, yes. Keep in mind that terms with now posts will probably display a 'nothing found'. If the first link works find, then its a permalink issue. You should [use this plug-in](http://wordpress.org/extend/plugins/monkeyman-rewrite-analyzer/) to diagnose it. A template won't effect a 404.
- 0
- 2012-08-15
- Stephen Harris
-
Hoprovato ad aggiungerenuoviprodottiea classificarli comemonitor,ilprimo collegamento ha dato un 404e così hafattoil secondo.Hoprovatoilplugin (aggiornerò la domanda con uno screenshot).I've tried adding new products and categorising them as monitors, the first link gave a 404 and so did the second one. Tried the plugin (I'll update the question with a screenshot).
- 0
- 2012-08-15
- Rob
-
Sembra chetunon abbia lavatoi tuoipermalink.Vai allapagina Impostazioni> Permalinke premi dinuovo "Salva"perforzare un aggiornamento delle regole di riscrittura.Sounds like you haven't flushed your permalinks. Go to the Settings > Permalinks page and just hit 'Save' again to force an update of the rewrite rules.
- 0
- 2012-08-15
- Tom Auger
-
- 2018-12-28
Riferimento: https://stackoverflow.com/questions/33888951/wordpress-custom -post-type-taxonomy-template
<?php get_header(); do_action('genesis_before_content_sidebar_wrap'); ?> <div id="content-sidebar-wrap"> <?php do_action('genesis_before_content'); ?> <div class="wrap"> <main class="content"> <?php $case_study_cat_slug = get_queried_object()->slug; $case_study_cat_name = get_queried_object()->name; ?> <h2><?php echo $case_study_cat_name; ?></h2> <?php $al_tax_post_args = array( 'post_type' => 'success_stories', // Your Post type Name that You Registered 'posts_per_page' => 999, 'order' => 'ASC', 'tax_query' => array( array( 'taxonomy' => 'success_stories_category', 'field' => 'slug', 'terms' => $case_study_cat_slug ) ) ); $al_tax_post_qry = new WP_Query($al_tax_post_args); if($al_tax_post_qry->have_posts()) : while($al_tax_post_qry->have_posts()) : $al_tax_post_qry->the_post(); echo '<div class="post-excerpt">'; ?> <h2 class="entry-title" itemprop="headline"><a href="<?php the_permalink(); ?>" class="entry-title-link"><?php the_title(); ?></a></h2> <div class="entry-content"> <?php echo excerpt(35); ?> </div> </div> <?php endwhile; endif; ?> </main> </div> </div> <?php do_action('genesis_after_content_sidebar_wrap'); get_footer();
Reference : https://stackoverflow.com/questions/33888951/wordpress-custom-post-type-taxonomy-template
<?php get_header(); do_action('genesis_before_content_sidebar_wrap'); ?> <div id="content-sidebar-wrap"> <?php do_action('genesis_before_content'); ?> <div class="wrap"> <main class="content"> <?php $case_study_cat_slug = get_queried_object()->slug; $case_study_cat_name = get_queried_object()->name; ?> <h2><?php echo $case_study_cat_name; ?></h2> <?php $al_tax_post_args = array( 'post_type' => 'success_stories', // Your Post type Name that You Registered 'posts_per_page' => 999, 'order' => 'ASC', 'tax_query' => array( array( 'taxonomy' => 'success_stories_category', 'field' => 'slug', 'terms' => $case_study_cat_slug ) ) ); $al_tax_post_qry = new WP_Query($al_tax_post_args); if($al_tax_post_qry->have_posts()) : while($al_tax_post_qry->have_posts()) : $al_tax_post_qry->the_post(); echo '<div class="post-excerpt">'; ?> <h2 class="entry-title" itemprop="headline"><a href="<?php the_permalink(); ?>" class="entry-title-link"><?php the_title(); ?></a></h2> <div class="entry-content"> <?php echo excerpt(35); ?> </div> </div> <?php endwhile; endif; ?> </main> </div> </div> <?php do_action('genesis_after_content_sidebar_wrap'); get_footer();
-
Perfavore ** [modifica] latua risposta **e aggiungi una spiegazione: **perché ** questopotrebbe risolvereilproblema?Please **[edit] your answer**, and add an explanation: **why** could that solve the problem?
- 0
- 2018-12-28
- fuxia
-
- 2017-08-10
Per questo,aggiungiil seguente codicenelfunctions.php (che sitrovanella cartella deltema):
add_action( 'init', 'create_cw_hierarchical_taxonomy', 0 ); //create a custom taxonomy name function create_cw_hierarchical_taxonomy() { $labels = array( 'name' => _x( 'Topics', 'taxonomy general name' ), 'singular_name' => _x( 'Topic', 'taxonomy singular name' ), 'search_items' => __( 'Search Topics' ), 'all_items' => __( 'All Topics' ), 'parent_item' => __( 'Parent Topic' ), 'parent_item_colon' => __( 'Parent Topic:' ), 'edit_item' => __( 'Edit Topic' ), 'update_item' => __( 'Update Topic' ), 'add_new_item' => __( 'Add New Topic' ), 'new_item_name' => __( 'New Topic Name' ), 'menu_name' => __( 'Topics' ), ); // taxonomy register register_taxonomy('topics',array('post'), array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'topic' ), )); }
L'hotrovato quie qui ho scoperto come creare unatassonomianongerarchica https://www.wpblog.com/create-custom-taxonomies-in -wordpress/
For this, add the following code in the functions.php (located in the theme folder):
add_action( 'init', 'create_cw_hierarchical_taxonomy', 0 ); //create a custom taxonomy name function create_cw_hierarchical_taxonomy() { $labels = array( 'name' => _x( 'Topics', 'taxonomy general name' ), 'singular_name' => _x( 'Topic', 'taxonomy singular name' ), 'search_items' => __( 'Search Topics' ), 'all_items' => __( 'All Topics' ), 'parent_item' => __( 'Parent Topic' ), 'parent_item_colon' => __( 'Parent Topic:' ), 'edit_item' => __( 'Edit Topic' ), 'update_item' => __( 'Update Topic' ), 'add_new_item' => __( 'Add New Topic' ), 'new_item_name' => __( 'New Topic Name' ), 'menu_name' => __( 'Topics' ), ); // taxonomy register register_taxonomy('topics',array('post'), array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'topic' ), )); }
I have found it here and here i found how to create Non-hierarchical Taxonomy https://www.wpblog.com/create-custom-taxonomies-in-wordpress/
Di seguito hoi seguenti che ho utilizzatoper creare untipo di articolopersonalizzatoe unatassonomiapersonalizzata.
Nella sezioneprodotti ho creato le categorie "monitor" & amp; "materiali di consumo".
Ho quindi creatoiltemplatetaxonomy-monitors.php,è chiamato correttamenteper la categoria deimonitor? Inoltre qual è l'URL che devo visitareper vedere solo la categoria dimonitor che utilizza quelmodello?
AGGIORNAMENTO