Commit 637c1a9e authored by Mathieu Mangeot's avatar Mathieu Mangeot
Browse files

Ajout des custom post type dans le functions.php

parent 7ad4fb1e
......@@ -44,8 +44,30 @@ register_nav_menus(array(
)
);
/*--------------------------------------------------------------
Création d'un custom post type pour des films
--------------------------------------------------------------*/
function creer_posttype() {
register_post_type( 'film',
array(
'labels' => array(
'name' => __( 'Films' ),
'singular_name' => __( 'film' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'films'),
'show_in_rest' => true,
)
);
}
// Hooking up our function to theme setup
add_action( 'init', 'creer_posttype' );
/*--------------------------------------------------------------
rest_allow_anonymous_comments
curl -X POST https://www.example.com/wp-json/wp/v2/comments?author=userid&author_email=your-email-address@website-address-here.com&author_name=Your%20Name%20Here&content=Your%20Comment%20Here&post=1604252
--------------------------------------------------------------*/
function filter_rest_allow_anonymous_comments() {
return true;
......
<?php get_header();
/* Exemple de template pour une page spécifique
* créer une page dans l'interface admin de WP
* et récupérer son slug
*
* + Affichage d'articles d'une catégorie spécifique
*/
$categorie = get_category_by_slug('slug');
$args = array( 'posts_per_page' => -1,
'category' => $categorie->term_id,
'orderby' => 'name',
'order' => 'ASC', );
$posts = get_posts($args);
?>
<section id='content'>
<h1>Template spécifique pour une page</h1>
<h2>Avec des articles d'une catégorie spécifique</h2>
<header>
<h1 style="text-align:center;"><code>the_title():</code> <?php the_title(); ?></h1>
</header>
<p><code>foreach($posts as $post): setup_postdata($post);</code></p>
<?php foreach ( $posts as $post ) : setup_postdata( $post ); ?> <!--Because the_content() works only inside a WP Loop -->
<div class="entry-content-page">
<p><code>the_content():</code></p>
<?php the_content(); ?> <!-- Page Content -->
</div><!-- .entry-content-page -->
<?php
endforeach; //resetting the page loop
wp_reset_postdata(); //resetting the post data
?>
</section>
</section>
<?php get_footer(); ?>
......@@ -5,7 +5,8 @@
// ajouter un com
// ajouter une action dans le function.php pour autoriser les commentaires anonymes avec l'API REST
// postid=25&comment=com&author=moi&email=a%40b.cd&url=&submit=Laisser+un+commentaire
// curl -X POST https://www.example.com/wp-json/wp/v2/comments?author=userid&author_email=your-email-address@website-address-here.com&author_name=Your%20Name%20Here&content=Your%20Comment%20Here&post=1604252
// userpass = "username:password"
function CallAPI($method, $url, $data = false, $userpass = false)
......@@ -50,7 +51,7 @@
echo $url;
$result = CallAPI('POST',$url);
echo $result;
// https://www.example.com/wp-json/wp/v2/comments?author=userid&author_email=your-email-address@website-address-here.com&author_name=Your%20Name%20Here&content=Your%20Comment%20Here&post=1604252
// curl -X POST https://www.example.com/wp-json/wp/v2/comments?author=userid&author_email=your-email-address@website-address-here.com&author_name=Your%20Name%20Here&content=Your%20Comment%20Here&post=1604252
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment