Ajout htmx
This commit is contained in:
parent
d7590b4603
commit
4e02f23fde
25
css/app.css
25
css/app.css
|
|
@ -574,15 +574,24 @@ video {
|
||||||
.mb-8{
|
.mb-8{
|
||||||
margin-bottom: 2rem
|
margin-bottom: 2rem
|
||||||
}
|
}
|
||||||
|
.mr-3{
|
||||||
|
margin-right: 0.75rem
|
||||||
|
}
|
||||||
.mt-4{
|
.mt-4{
|
||||||
margin-top: 1rem
|
margin-top: 1rem
|
||||||
}
|
}
|
||||||
|
.mt-8{
|
||||||
|
margin-top: 2rem
|
||||||
|
}
|
||||||
.block{
|
.block{
|
||||||
display: block
|
display: block
|
||||||
}
|
}
|
||||||
.inline-block{
|
.inline-block{
|
||||||
display: inline-block
|
display: inline-block
|
||||||
}
|
}
|
||||||
|
.inline{
|
||||||
|
display: inline
|
||||||
|
}
|
||||||
.flex{
|
.flex{
|
||||||
display: flex
|
display: flex
|
||||||
}
|
}
|
||||||
|
|
@ -648,6 +657,15 @@ video {
|
||||||
.transform{
|
.transform{
|
||||||
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))
|
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))
|
||||||
}
|
}
|
||||||
|
@keyframes spin{
|
||||||
|
|
||||||
|
to{
|
||||||
|
transform: rotate(360deg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.animate-spin{
|
||||||
|
animation: spin 1s linear infinite
|
||||||
|
}
|
||||||
.cursor-pointer{
|
.cursor-pointer{
|
||||||
cursor: pointer
|
cursor: pointer
|
||||||
}
|
}
|
||||||
|
|
@ -832,6 +850,10 @@ video {
|
||||||
--tw-text-opacity: 1;
|
--tw-text-opacity: 1;
|
||||||
color: rgb(17 24 39 / var(--tw-text-opacity))
|
color: rgb(17 24 39 / var(--tw-text-opacity))
|
||||||
}
|
}
|
||||||
|
.text-slate-400{
|
||||||
|
--tw-text-opacity: 1;
|
||||||
|
color: rgb(148 163 184 / var(--tw-text-opacity))
|
||||||
|
}
|
||||||
.text-white{
|
.text-white{
|
||||||
--tw-text-opacity: 1;
|
--tw-text-opacity: 1;
|
||||||
color: rgb(255 255 255 / var(--tw-text-opacity))
|
color: rgb(255 255 255 / var(--tw-text-opacity))
|
||||||
|
|
@ -957,6 +979,9 @@ article > *:not(.entry-content),
|
||||||
list-style-position: inside;
|
list-style-position: inside;
|
||||||
list-style-type: decimal
|
list-style-type: decimal
|
||||||
}
|
}
|
||||||
|
.htmx-request .htmx-indicator{
|
||||||
|
display: inline
|
||||||
|
}
|
||||||
#loginform-custom label{
|
#loginform-custom label{
|
||||||
margin-bottom: 0.5rem;
|
margin-bottom: 0.5rem;
|
||||||
display: block
|
display: block
|
||||||
|
|
|
||||||
|
|
@ -77,12 +77,21 @@
|
||||||
.mt-4 {
|
.mt-4 {
|
||||||
margin-top: 1rem
|
margin-top: 1rem
|
||||||
}
|
}
|
||||||
|
.mt-8 {
|
||||||
|
margin-top: 2rem
|
||||||
|
}
|
||||||
|
.mr-3 {
|
||||||
|
margin-right: 0.75rem
|
||||||
|
}
|
||||||
.block {
|
.block {
|
||||||
display: block
|
display: block
|
||||||
}
|
}
|
||||||
.inline-block {
|
.inline-block {
|
||||||
display: inline-block
|
display: inline-block
|
||||||
}
|
}
|
||||||
|
.inline {
|
||||||
|
display: inline
|
||||||
|
}
|
||||||
.flex {
|
.flex {
|
||||||
display: flex
|
display: flex
|
||||||
}
|
}
|
||||||
|
|
@ -104,6 +113,9 @@
|
||||||
.h-full {
|
.h-full {
|
||||||
height: 100%
|
height: 100%
|
||||||
}
|
}
|
||||||
|
.h-5 {
|
||||||
|
height: 1.25rem
|
||||||
|
}
|
||||||
.min-h-12 {
|
.min-h-12 {
|
||||||
min-height: 3rem
|
min-height: 3rem
|
||||||
}
|
}
|
||||||
|
|
@ -122,6 +134,9 @@
|
||||||
.w-full {
|
.w-full {
|
||||||
width: 100%
|
width: 100%
|
||||||
}
|
}
|
||||||
|
.w-5 {
|
||||||
|
width: 1.25rem
|
||||||
|
}
|
||||||
.min-w-max {
|
.min-w-max {
|
||||||
min-width: -moz-max-content;
|
min-width: -moz-max-content;
|
||||||
min-width: max-content
|
min-width: max-content
|
||||||
|
|
@ -148,6 +163,14 @@
|
||||||
.transform {
|
.transform {
|
||||||
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))
|
transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))
|
||||||
}
|
}
|
||||||
|
@keyframes spin {
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.animate-spin {
|
||||||
|
animation: spin 1s linear infinite
|
||||||
|
}
|
||||||
.cursor-pointer {
|
.cursor-pointer {
|
||||||
cursor: pointer
|
cursor: pointer
|
||||||
}
|
}
|
||||||
|
|
@ -336,6 +359,22 @@
|
||||||
--tw-text-opacity: 1;
|
--tw-text-opacity: 1;
|
||||||
color: rgb(255 255 255 / var(--tw-text-opacity))
|
color: rgb(255 255 255 / var(--tw-text-opacity))
|
||||||
}
|
}
|
||||||
|
.text-amber-500 {
|
||||||
|
--tw-text-opacity: 1;
|
||||||
|
color: rgb(245 158 11 / var(--tw-text-opacity))
|
||||||
|
}
|
||||||
|
.text-gray-300 {
|
||||||
|
--tw-text-opacity: 1;
|
||||||
|
color: rgb(209 213 219 / var(--tw-text-opacity))
|
||||||
|
}
|
||||||
|
.text-slate-200 {
|
||||||
|
--tw-text-opacity: 1;
|
||||||
|
color: rgb(226 232 240 / var(--tw-text-opacity))
|
||||||
|
}
|
||||||
|
.text-slate-400 {
|
||||||
|
--tw-text-opacity: 1;
|
||||||
|
color: rgb(148 163 184 / var(--tw-text-opacity))
|
||||||
|
}
|
||||||
.underline {
|
.underline {
|
||||||
text-decoration-line: underline
|
text-decoration-line: underline
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,3 +112,4 @@ add_filter( 'nav_menu_submenu_css_class', 'tailpress_nav_menu_add_submenu_class'
|
||||||
|
|
||||||
require_once(__DIR__ . '/includes/post-type.php');
|
require_once(__DIR__ . '/includes/post-type.php');
|
||||||
require_once(__DIR__ . '/includes/add-form.php');
|
require_once(__DIR__ . '/includes/add-form.php');
|
||||||
|
require_once(__DIR__ . '/includes/api.php');
|
||||||
|
|
|
||||||
63
htmx/events-home.php
Normal file
63
htmx/events-home.php
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$paged = $_GET['paged'];
|
||||||
|
//echo $paged;
|
||||||
|
// WP_Query arguments
|
||||||
|
$args = array(
|
||||||
|
'post_type' => 'evenements',
|
||||||
|
'posts_per_page' => 6,
|
||||||
|
'paged' => $paged,
|
||||||
|
'meta_key' => 'date_debut', // Nom du champ ACF
|
||||||
|
'orderby' => 'meta_value', // Trier par la valeur du champ
|
||||||
|
'order' => 'ASC', // Ordre croissant ('DESC' pour décroissant)
|
||||||
|
'meta_type' => 'DATE' // Préciser que c'est une date (important)
|
||||||
|
);
|
||||||
|
|
||||||
|
// The Query
|
||||||
|
$query = new WP_Query( $args );
|
||||||
|
?>
|
||||||
|
<tbody id="posts" hx-swap-oob="beforeend">
|
||||||
|
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
|
||||||
|
<?php
|
||||||
|
$date_debut = get_field('date_debut');
|
||||||
|
$date_fin = get_field('date_fin');
|
||||||
|
$code_postal = get_field('code_postal');
|
||||||
|
$organisme = get_field('organisme');
|
||||||
|
$lien_de_levenement = get_field('lien_de_levenement');
|
||||||
|
?>
|
||||||
|
<tr>
|
||||||
|
<td class="p-4 border-b border-slate-300"><?php echo $date_debut; ?></td>
|
||||||
|
<td class="p-4 border-b border-slate-300"><?php echo $date_fin; ?></td>
|
||||||
|
<td class="p-4 border-b border-slate-300"><?php echo $code_postal; ?></td>
|
||||||
|
<td class="p-4 border-b border-slate-300"><?php echo $organisme; ?></td>
|
||||||
|
<td class="p-4 border-b border-slate-300"><a href="<?php echo $lien_de_levenement; ?>" target="_blank"><?php the_title(); ?></a></td>
|
||||||
|
</tr>
|
||||||
|
<?php endwhile; else : ?>
|
||||||
|
<p><?php esc_html_e( "Il n'y a plus d'événements à charger." ); ?></p>
|
||||||
|
<?php endif; ?>
|
||||||
|
</tbody>
|
||||||
|
|
||||||
|
<?php
|
||||||
|
if ( $query->have_posts() ) :
|
||||||
|
?>
|
||||||
|
<button
|
||||||
|
id="more"
|
||||||
|
hx-get="/wp-json/htmx/v1/events-home?paged=<?php echo $paged+1; ?>"
|
||||||
|
hx-trigger="revealed"
|
||||||
|
hx-swap-oob="true"
|
||||||
|
class="bg-secondary py-2 px-4 mt-8 rounded-md text-white cursor-pointer mx-auto">
|
||||||
|
<svg class="text-slate-400 animate-spin inline mr-3 htmx-indicator hidden" viewBox="0 0 64 64" fill="none" xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="18" height="18">
|
||||||
|
<path
|
||||||
|
d="M32 3C35.8083 3 39.5794 3.75011 43.0978 5.20749C46.6163 6.66488 49.8132 8.80101 52.5061 11.4939C55.199 14.1868 57.3351 17.3837 58.7925 20.9022C60.2499 24.4206 61 28.1917 61 32C61 35.8083 60.2499 39.5794 58.7925 43.0978C57.3351 46.6163 55.199 49.8132 52.5061 52.5061C49.8132 55.199 46.6163 57.3351 43.0978 58.7925C39.5794 60.2499 35.8083 61 32 61C28.1917 61 24.4206 60.2499 20.9022 58.7925C17.3837 57.3351 14.1868 55.199 11.4939 52.5061C8.801 49.8132 6.66487 46.6163 5.20749 43.0978C3.7501 39.5794 3 35.8083 3 32C3 28.1917 3.75011 24.4206 5.2075 20.9022C6.66489 17.3837 8.80101 14.1868 11.4939 11.4939C14.1868 8.80099 17.3838 6.66487 20.9022 5.20749C24.4206 3.7501 28.1917 3 32 3L32 3Z"
|
||||||
|
stroke="currentColor" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"></path>
|
||||||
|
<path
|
||||||
|
d="M32 3C36.5778 3 41.0906 4.08374 45.1692 6.16256C49.2477 8.24138 52.7762 11.2562 55.466 14.9605C58.1558 18.6647 59.9304 22.9531 60.6448 27.4748C61.3591 31.9965 60.9928 36.6232 59.5759 40.9762"
|
||||||
|
stroke="currentColor" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"
|
||||||
|
class="text-white"></path>
|
||||||
|
</svg>
|
||||||
|
Plus d'événements
|
||||||
|
</button>
|
||||||
|
<?php
|
||||||
|
endif;
|
||||||
|
?>
|
||||||
40
includes/api.php
Normal file
40
includes/api.php
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
// AJOUT ROUTE POUR HTMX
|
||||||
|
add_action('rest_api_init', function () {
|
||||||
|
register_rest_route('htmx/v1', '/events-home', [
|
||||||
|
'methods' => 'GET',
|
||||||
|
'callback' => 'load_custom_template',
|
||||||
|
'permission_callback' => '__return_true', // Autorise l'accès à tous les utilisateurs
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
function load_custom_template($request) {
|
||||||
|
// Nom du fichier de template à inclure (ex. : 'custom-template.php' dans votre thème)
|
||||||
|
$template = locate_template('htmx/events-home.php');
|
||||||
|
|
||||||
|
if ($template) {
|
||||||
|
// Capture la sortie du template pour l'inclure dans la réponse
|
||||||
|
ob_start();
|
||||||
|
include $template;
|
||||||
|
$content = ob_get_clean();
|
||||||
|
|
||||||
|
header('Content-Type: text/html; charset=UTF-8');
|
||||||
|
echo $content;
|
||||||
|
exit; // Important pour éviter que WordPress ajoute des données JSON supplémentaires
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retourne une erreur si le fichier template est introuvable
|
||||||
|
header('Content-Type: text/html; charset=UTF-8', true, 404);
|
||||||
|
echo 'Template introuvable.';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ENQUEUE HTMX
|
||||||
|
add_action('wp_enqueue_scripts', 'add_scripts');
|
||||||
|
function add_scripts(){
|
||||||
|
wp_register_script( 'htmx', 'https://unpkg.com/htmx.org@2.0.3', false, null, true);
|
||||||
|
if(is_front_page()):
|
||||||
|
wp_enqueue_script( 'htmx' );
|
||||||
|
endif;
|
||||||
|
}
|
||||||
|
|
@ -40,3 +40,8 @@ article > *:not(.entry-content),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.htmx-request .htmx-indicator{
|
||||||
|
@apply inline;
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
// WP_Query arguments
|
// WP_Query arguments
|
||||||
$args = array(
|
$args = array(
|
||||||
'post_type' => 'evenements',
|
'post_type' => 'evenements',
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => 6,
|
||||||
'meta_key' => 'date_debut', // Nom du champ ACF
|
'meta_key' => 'date_debut', // Nom du champ ACF
|
||||||
'orderby' => 'meta_value', // Trier par la valeur du champ
|
'orderby' => 'meta_value', // Trier par la valeur du champ
|
||||||
'order' => 'ASC', // Ordre croissant ('DESC' pour décroissant)
|
'order' => 'ASC', // Ordre croissant ('DESC' pour décroissant)
|
||||||
|
|
@ -12,6 +12,7 @@ $args = array(
|
||||||
|
|
||||||
// The Query
|
// The Query
|
||||||
$query = new WP_Query( $args );
|
$query = new WP_Query( $args );
|
||||||
|
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
@ -27,7 +28,7 @@ $query = new WP_Query( $args );
|
||||||
<th class="p-4 border-b border-slate-300 bg-slate-200">Titre</th>
|
<th class="p-4 border-b border-slate-300 bg-slate-200">Titre</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody id="posts">
|
||||||
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
|
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
|
||||||
<?php
|
<?php
|
||||||
$date_debut = get_field('date_debut');
|
$date_debut = get_field('date_debut');
|
||||||
|
|
@ -44,9 +45,28 @@ $query = new WP_Query( $args );
|
||||||
<td class="p-4 border-b border-slate-300"><a href="<?php echo $lien_de_levenement; ?>" target="_blank"><?php the_title(); ?></a></td>
|
<td class="p-4 border-b border-slate-300"><a href="<?php echo $lien_de_levenement; ?>" target="_blank"><?php the_title(); ?></a></td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endwhile; else : ?>
|
<?php endwhile; else : ?>
|
||||||
<p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
|
<p><?php esc_html_e( "Il n'y a plus d'événements à charger." ); ?></p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="pagination flex flex-col items-center">
|
||||||
|
<button
|
||||||
|
id="more"
|
||||||
|
hx-get="/wp-json/htmx/v1/events-home?paged=<?php echo $paged+1; ?>"
|
||||||
|
hx-trigger="revealed"
|
||||||
|
class="bg-secondary py-2 px-4 mt-8 rounded-md text-white cursor-pointer mx-auto">
|
||||||
|
<svg class="text-slate-400 animate-spin inline mr-3 htmx-indicator hidden" viewBox="0 0 64 64" fill="none" xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="18" height="18">
|
||||||
|
<path
|
||||||
|
d="M32 3C35.8083 3 39.5794 3.75011 43.0978 5.20749C46.6163 6.66488 49.8132 8.80101 52.5061 11.4939C55.199 14.1868 57.3351 17.3837 58.7925 20.9022C60.2499 24.4206 61 28.1917 61 32C61 35.8083 60.2499 39.5794 58.7925 43.0978C57.3351 46.6163 55.199 49.8132 52.5061 52.5061C49.8132 55.199 46.6163 57.3351 43.0978 58.7925C39.5794 60.2499 35.8083 61 32 61C28.1917 61 24.4206 60.2499 20.9022 58.7925C17.3837 57.3351 14.1868 55.199 11.4939 52.5061C8.801 49.8132 6.66487 46.6163 5.20749 43.0978C3.7501 39.5794 3 35.8083 3 32C3 28.1917 3.75011 24.4206 5.2075 20.9022C6.66489 17.3837 8.80101 14.1868 11.4939 11.4939C14.1868 8.80099 17.3838 6.66487 20.9022 5.20749C24.4206 3.7501 28.1917 3 32 3L32 3Z"
|
||||||
|
stroke="currentColor" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"></path>
|
||||||
|
<path
|
||||||
|
d="M32 3C36.5778 3 41.0906 4.08374 45.1692 6.16256C49.2477 8.24138 52.7762 11.2562 55.466 14.9605C58.1558 18.6647 59.9304 22.9531 60.6448 27.4748C61.3591 31.9965 60.9928 36.6232 59.5759 40.9762"
|
||||||
|
stroke="currentColor" stroke-width="5" stroke-linecap="round" stroke-linejoin="round"
|
||||||
|
class="text-white"></path>
|
||||||
|
</svg>
|
||||||
|
Plus d'événements
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
Loading…
Reference in New Issue
Block a user