Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hawkidoki/a938a572d23a6b1f6da14b053496e9af to your computer and use it in GitHub Desktop.
Save hawkidoki/a938a572d23a6b1f6da14b053496e9af to your computer and use it in GitHub Desktop.
<?php
/**
* Dynamic Post Type Subpages
* Exemple Simple
*/
add_filter('hwk/post_types/subpages', 'hwk_post_type_film_subpages_simple');
function hwk_post_type_film_subpages_simple($settings){
$settings[] = array(
'post_type' => 'film',
'meta_prefix' => 'ptsp_',
'pages' => array(
// Result: /film/interstellar/acteurs
array(
'title' => 'Acteurs', // Titre qui sert à l'administration.
'name' => 'acteurs', // Slug des Query Vars & URL de base de la Sous-Page
'rewrite' => false, // Activation/Désactivation du Permalien dynamique.
'primary' => false, // Remplacer l'URL de base du Post Type. Unique, un seul possible.
'pagination' => false, // Activer la pagination (/page/2/)
'template' => 'single-film-acteurs.php' // Fichier de template. Peut être vide
),
// Result: /film/interstellar/critiques
array(
'title' => 'Critiques',
'name' => 'critiques',
'rewrite' => false,
'primary' => false,
'pagination' => false,
'template' => 'single-film-critiques.php'
),
)
);
return $settings;
}
/**
* Dynamic Post Type Subpages
* Exemple Avancé
*/
add_filter('hwk/post_types/subpages', 'hwk_post_type_film_subpages_advanced');
function hwk_post_type_film_subpages_advanced($settings){
$settings[] = array(
'post_type' => 'film',
'meta_prefix' => 'ptsp_',
'pages' => array(
// Result: /film/interstellar/fiche
// Utilisation de primary = true.
// Fiche devient la nouvelle URL principale de la single 'film'
array(
'title' => 'Fiche',
'name' => 'fiche',
'rewrite' => false,
'primary' => true,
'pagination' => false,
'template' => 'single-film-fiche.php'
),
// Result: /film/interstellar/acteurs-{post_meta:ptsp_acteurs}-liste
array(
'title' => 'Acteurs',
'name' => 'acteurs',
'rewrite' => array(
'prepend' => 'acteurs',
'append' => 'liste',
),
'primary' => false,
'pagination' => true,
'template' => 'single-film-acteurs.php'
),
// Result: /film/interstellar/critiques-{post_meta:ptsp_critiques}
array(
'title' => 'Critiques',
'name' => 'critiques',
'rewrite' => array(
'prepend' => 'critiques',
),
'primary' => false,
'pagination' => true,
'template' => 'single-film-critiques.php'
),
)
);
return $settings;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment