feat: ajout des romans

Fixes #14
This commit is contained in:
Kazhnuz 2021-01-04 13:05:09 +01:00
parent fd5d3a7e5f
commit ffffe92af3
3 changed files with 209 additions and 0 deletions

View file

@ -248,3 +248,75 @@ function kspace_update_profile_fields( $user_id ) {
update_user_meta( $user_id, 'infodata', $_POST['infodata'] ); update_user_meta( $user_id, 'infodata', $_POST['infodata'] );
} }
/* 4. Romans
*
* Permet de catégoriser des chapitres ensemble, via une catégorie spécifiques.
*
*/
register_taxonomy('roman', 'post',
array(
'label' => 'Roman',
'labels' => array(
'name' => 'Romans',
'singular_name' => 'Roman',
'all_items' => 'Tous les romans',
'edit_item' => 'Éditer le roman',
'view_item' => 'Voir le roman',
'update_item' => 'Mettre à jour le roman',
'add_new_item' => 'Ajouter un roman',
'new_item_name' => 'Nouveau roman',
'search_items' => 'Rechercher parmi les romans',
'popular_items' => 'Romans les plus utilisés'),
'rewrite' => array('slug' => 'roman'),
'hierarchical' => false,
'public' => true,
'hierarchical' => true,
'show_in_nav_menus' => true,
'has_archive' => true,
)
);
register_taxonomy_for_object_type( 'roman', 'post' );
// 1.2 - Ajout/Modif du niveau du flag
function romans_taxonomy_custom_fields($tag) {
// Check for existing taxonomy meta for the term you're editing
$t_id = $tag->term_id; // Get the ID of the term you're editing
$term_meta = get_option( "taxonomy_term_$t_id" ); // Do the check
?>
<tr class="form-field">
<th scope="row" valign="top">
<label for="niveau"><?php _e('Couverture du roman'); ?></label>
</th>
<td>
<input type="text" name="term_meta[cover]" id="term_meta[cover]" size="25" style="width:60%;" value="<?php echo $term_meta['cover'] ? $term_meta['cover'] : ''; ?>"><br />
<span class="description"><?php _e('La couverture du roman, sous format URL'); ?></span>
</td>
</tr>
<?php
}
function romans_taxonomy_custom_fields_add( $taxonomy ) {
// Check for existing taxonomy meta for the term you're editing
$t_id = $tag->term_id; // Get the ID of the term you're editing
$term_meta = get_option( "taxonomy_term_$t_id" ); // Do the check
?>
<div class="form-field">
<label for="term_meta[cover]"><?php _e('Couverture du roman'); ?></label>
<input type="text" name="term_meta[cover]" id="term_meta[cover]" />
<p><?php _e('La couverture du roman, sous format URL)'); ?>.</p>
</div>
<?php
}
// Ajout des fields
add_action( 'roman_edit_form_fields', 'romans_taxonomy_custom_fields', 10, 2 );
add_action( 'roman_add_form_fields', 'romans_taxonomy_custom_fields_add' );
add_action( 'created_roman', 'save_taxonomy_custom_fields' );
add_action( 'edited_roman', 'save_taxonomy_custom_fields', 10, 2 );

71
page-roman.php Normal file
View file

@ -0,0 +1,71 @@
<?php /* Template Name: page-romans */ ?>
<?php get_header(); ?> <!-- ouvrir header,php -->
<main>
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<div class="flex-that">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class='breadcrumb-item'><a href='<?php echo site_url(); ?>'>kazhnuz.space</a></li><li class="breadcrumb-item" aria-current="page"><span class="active"><i class="fa fa-folder-open"></i> <?php echo the_title(); ?></span></li>
</ol>
</nav>
</div>
<?php endwhile; ?>
<?php endif; ?>
<div class="previews-section">
<?
$terms = get_terms(
array(
'taxonomy' => 'roman',
'hide_empty' => false,
)
);
// Check if any term exists
if ( ! empty( $terms ) && is_array( $terms ) ) {
// Run a loop and print them all
foreach ( $terms as $term ) { ?>
<article class="card card-preview card-primary">
<a href="<?php echo esc_url( get_term_link( $term ) ) ?>" class="preview-link">
<div class="preview-item">
<div class="preview-content" style="background-image:url('<?php
$tag_id = $term->term_id;
$term_meta = get_option( "taxonomy_term_$tag_id" );
echo $term_meta['cover'];
?> ');"></div>
<div class="preview-overlay">
<h1 class="card-header"><?php echo $term->name; ?></h1>
<div class="preview-metadata">
<div class="metadata-pills">
</div>
<div class="comment-text"><?php echo $term->count; ?> Chapitres</div>
</div>
</div>
</div>
</a>
</article>
<?php }
}
?>
</div>
</main>
<aside class="sidebar">
<?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
<div class="card card-info">
<div class="card-header"><i class="fa fa-folder-open"></i> <?php the_title(); ?></div>
<div class="card-body">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php include(TEMPLATEPATH . '/components/sidebar-content.php'); ?>
</aside>
<?php get_footer(); ?>

66
taxonomy-roman.php Normal file
View file

@ -0,0 +1,66 @@
<?php get_header(); ?> <!-- ouvrir header,php -->
<main>
<?php $tag = get_category( get_query_var( 'roman' ) );
$tag_id = get_queried_object()->term_id;?>
<div class="flex-that">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="<?php echo site_url(); ?>">kazhnuz.space</a></li><li class="breadcrumb-item" aria-current="page"><span class="active"><i class="fa fa-book"></i> <?php echo single_cat_title(); ?></span></li>
</ol>
</nav>
<div class="rss">
<? echo '<a href="' . get_tag_link( $tag_id ) . 'feed/" title="RSS de la categorie" class="btn btn-orange" /><i class="fa fa-rss"></i></a>'; ?>
</div>
</div>
<img class="cover" src="<?php
$term_meta = get_option( "taxonomy_term_$tag_id" );
echo $term_meta['cover'];
?>">
<div class="roman">
<div class="card">
<h1><?php echo single_cat_title(); ?></h1>
<div class="card-body">
<?php echo tag_description();?>
</div>
</div>
<?php
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'roman',
'field' => 'term_id',
'terms' => $tag_id // you need to know the term_id of your term "example 1"
),
),
'posts_per_page' => -1,
'order' => 'ASC',
);
$query = new WP_Query( $args );
?>
<div class="card card-primary">
<div class="card-header"><i class="fa fa-list"></i> Chapitres</div>
<div class="card-menu">
<?php if($query->have_posts()) : ?>
<?php $i = 1; ?>
<?php while($query->have_posts()) : $query->the_post(); ?>
<a href="<?php the_permalink(); ?>" class="menu-element">
<span class="text-dark">
<strong>Chapitre <?php echo $i++; ?>.</strong>
<?php the_title(); ?>
</span>
<span>
<em class="text-dark"><?php the_time('d/m/Y') ?></em>
</span>
</a>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
</div>
</main>
<?php get_sidebar(); ?>
<?php get_footer(); ?>