From 12b0baf4e10f7e330019939730dc966a0052d66f Mon Sep 17 00:00:00 2001 From: Antoine M Date: Thu, 20 Jul 2023 11:54:51 +0200 Subject: [PATCH] handling publications brochures --- css/admin-style.css | 8 ++ css/app.css | 4 + css/editor-style.css | 4 + functions.php | 1 + includes/admin.php | 6 +- includes/post-brochures.php | 22 +++++ includes/post_types.php | 146 ++++++++++++++++++---------------- includes/taxonomy.php | 11 ++- resources/css/admin-style.css | 8 +- style.css | 4 +- taxonomy-thematiques.php | 54 +++++++++++++ 11 files changed, 194 insertions(+), 74 deletions(-) create mode 100644 includes/post-brochures.php create mode 100644 taxonomy-thematiques.php diff --git a/css/admin-style.css b/css/admin-style.css index 68ccfdd..7b12dc9 100644 --- a/css/admin-style.css +++ b/css/admin-style.css @@ -4,4 +4,12 @@ #menu-posts { border-top: 1px solid rgba(255, 255, 255, 0.2) !important; +} + +#menu-posts-conseils { + border-top: 1px solid rgba(255, 255, 255, 0.2) !important; +} + +#toplevel_page_theme-general-settings { + border-bottom: 1px solid rgba(255, 255, 255, 0.2) !important; } diff --git a/css/app.css b/css/app.css index 31b7d6a..185f360 100644 --- a/css/app.css +++ b/css/app.css @@ -903,6 +903,10 @@ video { -moz-osx-font-smoothing: grayscale; } +.filter { + filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow); +} + .alignfull { margin: 2rem calc(50% - 50vw) !important; max-width: 100vw !important; diff --git a/css/editor-style.css b/css/editor-style.css index 7d017bd..c0e40dc 100644 --- a/css/editor-style.css +++ b/css/editor-style.css @@ -350,6 +350,10 @@ -moz-osx-font-smoothing: grayscale } +.filter { + filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow) +} + .alignfull { margin: 2rem calc(50% - 50vw) !important; max-width: 100vw !important; diff --git a/functions.php b/functions.php index c4ec850..15051aa 100644 --- a/functions.php +++ b/functions.php @@ -5,6 +5,7 @@ require_once(__DIR__ . '/includes/rooting.php'); require_once(__DIR__ . '/includes/init.php'); require_once(__DIR__ . '/includes/blocks.php'); require_once(__DIR__ . '/includes/post_types.php'); +require_once(__DIR__ . '/includes/post-brochures.php'); require_once(__DIR__ . '/includes/admin.php'); require_once(__DIR__ . '/includes/logos.php'); require_once(__DIR__ . '/includes/taxonomy.php'); diff --git a/includes/admin.php b/includes/admin.php index 5907dcd..e2de08b 100644 --- a/includes/admin.php +++ b/includes/admin.php @@ -17,7 +17,7 @@ function register_theme_settings_option_page() 'menu_slug' => 'theme-general-settings', 'capability' => 'activate_plugins', 'redirect' => false, - 'position' => 9, + 'position' => 20, )); } } @@ -119,6 +119,8 @@ function add_acf_posts_columns($columns) return array_merge($new_admin_col_arrays); } add_filter('manage_conseils_posts_columns', 'add_acf_posts_columns'); +add_filter('manage_fiche-questions_posts_columns', 'add_acf_posts_columns'); +add_filter('manage_brochures_posts_columns', 'add_acf_posts_columns'); // CUSTOMISATION DE LA COLONNE POUR AFFICHER : THEMATIQUE PARENT > THEMATIQUE function handle_posts_custom_columns($column, $post_id) @@ -135,3 +137,5 @@ function handle_posts_custom_columns($column, $post_id) echo ''; } add_action('manage_conseils_posts_custom_column', 'handle_posts_custom_columns', 10, 2); +add_action('manage_fiche-questions_posts_custom_column', 'handle_posts_custom_columns', 10, 2); +add_action('manage_brochures_posts_custom_column', 'handle_posts_custom_columns', 10, 2); diff --git a/includes/post-brochures.php b/includes/post-brochures.php new file mode 100644 index 0000000..8020dae --- /dev/null +++ b/includes/post-brochures.php @@ -0,0 +1,22 @@ +name; + } + + + wp_update_post($my_post); +} +add_action('acf/save_post', 'homegrade_brochure_post_title_updater', 20); diff --git a/includes/post_types.php b/includes/post_types.php index 9157087..39df99f 100644 --- a/includes/post_types.php +++ b/includes/post_types.php @@ -44,25 +44,6 @@ add_action('admin_menu', 'change_menu_icon'); // #### POST TYPES function create_posttype() { - - register_post_type( - 'fiche-questions', - array( - 'labels' => array( - 'name' => __('Questions', 'homegrade-theme__texte-backoffice'), - 'singular_name' => __('Question', 'homegrade-theme__texte-backoffice') - ), - 'public' => true, - 'has_archive' => true, - 'rewrite' => array('slug' => 'fiche-question'), - 'show_in_rest' => true, - 'menu_icon' => 'dashicons-admin-comments', - 'menu_icon' => 'dashicons-editor-help', - - 'menu_position' => 4, - 'supports' => array('title', 'custom-fields', 'excerpt'), - ) - ); register_post_type( 'conseils', array( @@ -75,13 +56,45 @@ function create_posttype() 'has_archive' => true, 'show_in_rest' => true, 'menu_icon' => 'dashicons-pressthis', - 'menu_position' => 4, - // 'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'), + 'menu_position' => 2, + 'supports' => array('title', 'editor', 'page-attributes'), // 'supports' => array('title', 'custom-fields', 'editor'), ) ); - + register_post_type( + 'brochures', + array( + 'labels' => array( + 'name' => __('Brochures', 'homegrade-theme__texte-backoffice'), + 'singular_name' => __('Brochure', 'homegrade-theme__texte-backoffice') + ), + 'hierarchical' => true, + 'public' => true, + 'has_archive' => true, + 'show_in_rest' => true, + 'menu_icon' => 'dashicons-book', + 'menu_position' => 2, + 'position' => 2, + 'supports' => array('custom-fields', 'page-attributes'), + ) + ); + register_post_type( + 'fiche-questions', + array( + 'labels' => array( + 'name' => __('Questions', 'homegrade-theme__texte-backoffice'), + 'singular_name' => __('Question', 'homegrade-theme__texte-backoffice') + ), + 'public' => true, + 'has_archive' => true, + 'rewrite' => array('slug' => 'fiche-question'), + 'show_in_rest' => true, + 'menu_icon' => 'dashicons-editor-help', + 'menu_position' => 4, + 'supports' => array('title', 'custom-fields', 'editor', 'excerpt'), + ) + ); register_post_type( 'vocabulaire', array( @@ -93,57 +106,54 @@ function create_posttype() 'has_archive' => true, 'rewrite' => array('slug' => 'fiche'), 'show_in_rest' => true, - // 'menu_icon' => 'dashicons-image-filter', - 'menu_icon' => 'dashicons-media-spreadsheet', 'menu_icon' => 'dashicons-info-outline', - - 'menu_position' => 4, - 'supports' => array('title', 'custxom-fields'), - - + 'menu_position' => 5.1, + 'supports' => array('title', 'custom-fields'), ) ); } + add_action('init', 'create_posttype'); -// function remove_editor() -// { -// if (isset($_GET['post'])) { -// $id = $_GET['post']; -// $template = get_post_meta($id, '_wp_page_template', true); -// switch ($template) { -// case 'template_01.php': -// case 'template_02.php': -// case 'template_03.php': -// case 'template_04.php': -// // the below removes 'editor' support for 'pages' -// // if you want to remove for posts or custom post types as well -// // add this line for posts: -// // remove_post_type_support('post', 'editor'); -// // add this line for custom post types and replace -// // custom-post-type-name with the name of post type: -// // remove_post_type_support('custom-post-type-name', 'editor'); -// remove_post_type_support('page', 'editor'); -// break; -// default: -// // Don't remove any other template. -// break; -// } -// } -// } -// add_action('init', 'remove_editor'); - -// add_action( 'admin_init', 'hide_editor' ); - -// function hide_editor() { -// $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ; -// if( !isset( $post_id ) ) return; - -// $template_file = get_post_meta($post_id, '_wp_page_template', true); - -// if($template_file == 'submit.php'){ // edit the template name -// remove_post_type_support('page', 'editor'); -// } -// } \ No newline at end of file +/* ---------------------------------------------------------------------- + POST TYPE ORDER + ------------------------------------------------------------------------*/ +/** + * Activates the 'menu_order' filter and then hooks into 'menu_order' + */ +add_filter('custom_menu_order', function () { + return true; +}); +add_filter('menu_order', 'my_new_admin_menu_order'); +/** + * Filters WordPress' default menu order + */ +function my_new_admin_menu_order($menu_order) +{ + // define your new desired menu positions here + // for example, move 'upload.php' to position #9 and built-in pages to position #1 + $new_positions = array( + 'upload.php' => 9, + // 'edit.php?post_type=page' => 1, + 'edit.php?post_type=conseils' => 1, + 'edit.php?post_type=fiche-questions' => 2, + 'edit.php?post_type=brochures' => 3, + 'edit.php?post_type=vocabulaire' => 4, + ); + // helper function to move an element inside an array + function move_element(&$array, $a, $b) + { + $out = array_splice($array, $a, 1); + array_splice($array, $b, 0, $out); + } + // traverse through the new positions and move + // the items if found in the original menu_positions + foreach ($new_positions as $value => $new_index) { + if ($current_index = array_search($value, $menu_order)) { + move_element($menu_order, $current_index, $new_index); + } + } + return $menu_order; +}; diff --git a/includes/taxonomy.php b/includes/taxonomy.php index 411d361..5c2e1bb 100644 --- a/includes/taxonomy.php +++ b/includes/taxonomy.php @@ -40,7 +40,7 @@ function undo_create_term($term_id, $tt_id, $taxonomy) function add_custom_taxonomies() { // ————— Thématiques ————— - register_taxonomy('thematiques', ['fiche-questions', 'conseils'], array( + register_taxonomy('thematiques', ['fiche-questions', 'conseils', 'brochures'], array( // 'hierarchical' => true, 'labels' => array( 'name' => __('Thématiques', 'homegrade-theme__texte-backoffice'), @@ -56,12 +56,19 @@ function add_custom_taxonomies() 'menu_name' => __('Thématiques', 'homegrade-theme__texte-backoffice'), ), 'public' => true, - 'show_in_rest' => false, // Needed for tax to appear in Gutenberg editor + 'show_in_rest' => true, // Needed for tax to appear in Gutenberg editor 'show_ui' => true, 'show_admin_column' => false, 'hierarchical' => true, // This will allow URL's like "/locations/boston/cambridge/" 'show_in_quick_edit' => false, 'meta_box_cb' => false, + 'rewrite' => array( + 'slug' => 'nos-conseils-thematiques', + // 'with_front' => false, + 'hierarchical' => true, + 'has_archive' => true + ), + )); diff --git a/resources/css/admin-style.css b/resources/css/admin-style.css index 49c6001..e18e9f1 100644 --- a/resources/css/admin-style.css +++ b/resources/css/admin-style.css @@ -2,5 +2,11 @@ background: red !important; } */ #menu-posts { - border-top: 1px solid rgba(255, 255, 255, 0.2) !important; + border-top: 1px solid rgba(255, 255, 255, 0.2) !important; +} +#menu-posts-conseils { + border-top: 1px solid rgba(255, 255, 255, 0.2) !important; +} +#toplevel_page_theme-general-settings { + border-bottom: 1px solid rgba(255, 255, 255, 0.2) !important; } diff --git a/style.css b/style.css index f21447d..750e41e 100644 --- a/style.css +++ b/style.css @@ -1,7 +1,7 @@ /* Theme Name: Homegrade_Theme -Author: Deligraph -Author URI: https://deligraph.com/ +Author: Deligraph +Author URI: https://deligraph.com/ Version: 1.0.0 Text Domain: homegrade-theme__texte-fonctionnel */ diff --git a/taxonomy-thematiques.php b/taxonomy-thematiques.php new file mode 100644 index 0000000..87edd6d --- /dev/null +++ b/taxonomy-thematiques.php @@ -0,0 +1,54 @@ +'; +print_r($term); +print_r(is_tax('thematiques', 'thematiques')); +echo ''; + +$args = array( + 'posts_per_page' => 1, + 'post_type' => 'conseils', + 'tax_query' => array( + array( + 'slug' => 'locations', + 'taxonomy' => 'thematiques', + 'field' => 'slug', + 'terms' => $term->slug, + 'include_children' => false, + ) + ) +); +$query_thematique_posts = new WP_Query($args); +$thematique_related_page = $query_thematique_posts->posts[0]; + + + +if ($term->parent == 0) { + $args = array( + 'child_of' => $term->term_id, + 'taxonomy' => $term->taxonomy, + 'hide_empty' => 0, + 'hierarchical' => true, + 'depth' => 1, + ); + wp_list_categories($args); +} + +// echo '
';
+// print_r($thematique_related_page);
+// echo '
'; + + +// echo $the_query->posts[0]->post_content; +?> + +
+ + post_content; + ?> +
+ +