plugin succed to : get published posts
+ print them onlly in map page + wordpress plugin directory changed to save work in git
This commit is contained in:
79
srcs/plugins/map_prof/map_prof.php
Executable file
79
srcs/plugins/map_prof/map_prof.php
Executable file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* @package map_prof
|
||||
* @version 1.0.0
|
||||
*/
|
||||
/*
|
||||
Plugin Name: map_prof
|
||||
Plugin URI:
|
||||
Description: add/remove locations on map at publication/deletion of posts
|
||||
Author: hugogogo
|
||||
Version: 1.0.0
|
||||
Author URI:
|
||||
*/
|
||||
|
||||
$markers = array("two");
|
||||
|
||||
add_action('draft_to_publish', 'add_marker');
|
||||
|
||||
function add_marker(){
|
||||
array_push($markers, "one");
|
||||
}
|
||||
|
||||
add_action('the_content', 'print_content', 1);
|
||||
|
||||
function print_content($content){
|
||||
|
||||
// print only on the page 'map', and other conditions
|
||||
// https://developer.wordpress.org/reference/hooks/the_content/
|
||||
if (!( is_page('map') && in_the_loop() && is_main_query() ))
|
||||
return $content;
|
||||
|
||||
// https://developer.wordpress.org/reference/functions/get_posts/
|
||||
$get_posts_args = array(
|
||||
'numberposts' => -1,
|
||||
'post_status' => 'publish',
|
||||
);
|
||||
|
||||
$posts_list = get_posts($get_posts_args);
|
||||
$content .= "<p>";
|
||||
$content .= "nb posts published : ";
|
||||
$content .= count($posts_list);
|
||||
$content .= "</p>";
|
||||
foreach ($posts_list as $post_value) {
|
||||
$content .= "<div>";
|
||||
$content .= "- post title: [";
|
||||
$content .= $post_value->post_title;
|
||||
$content .= "] - content: [";
|
||||
$content .= $post_value->post_content;
|
||||
$content .= "]";
|
||||
$content .= "</div>";
|
||||
}
|
||||
|
||||
// TESTS : print posts full content
|
||||
//
|
||||
//$posts_list = get_posts($args);
|
||||
//$content .= "<p>";
|
||||
//$content .= "nb posts published : ";
|
||||
//$content .= count($posts_list);
|
||||
//$content .= "</p>";
|
||||
//foreach ($posts_list as $post_key => $post_value) {
|
||||
// $content .= "<p>";
|
||||
// $content .= "post content : ";
|
||||
// $content .= $post_key;
|
||||
// $content .= " : ";
|
||||
// $content .= "<br>";
|
||||
// foreach ($post_value as $key => $value) {
|
||||
// $content .= "- [";
|
||||
// $content .= $key;
|
||||
// $content .= "]: [";
|
||||
// $content .= $value;
|
||||
// $content .= "]<br>";
|
||||
// }
|
||||
// $content .= "</p>";
|
||||
//}
|
||||
|
||||
return $content;
|
||||
};
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user