General: Here a plugin that will display a list of posts will be demonstrated.

Read more about developer resources here: https://developer.wordpress.org/

Top-10-WordPress-Plugins-That-You-Need-To-Be-Using-In-2014

 

Step 01: Plugin name will be DisplayListOfPosts

Step 02: Create a directory under wordpress-root\wp-content\plugins\DisplayListOfPosts

Step 03: Create a file under that directory called: DisplayListOfPosts.php

Step 04: The the following content to the plugin file:

<?php

/*
Plugin Name: Display List of Posts
Plugin URI: http://www.flash-jet.com
Description: A plugin demo that will display list of Posts
Version: 1.0
Author: Gabriel Magen
Author URI: http://www.flash-jet.com
*/

?>

Step 05: From wordpress admin panel, activate the new plugin.

Step 06: Here an action of adding option to admin menu will be demonstrated. Add the following code to file:

//adding action to admin menu and bind it to function name

add_action(‘admin_menu’,’DisplayListOfPosts_admin_actions’);

function DisplayListOfPosts_admin_actions() {

add_options_page(‘Display List Of Posts’,’Display List Of Posts’,’manage_options’,__FILE__,’DisplayListOfPosts_admin’);

//add_options_page(HTML Page title,Settings Submenu,hook only admin can see,php constant,function that will display the posts list);

}

function DisplayListOfPosts_admin() {

}

Step 07: Replace function DisplayListOfPosts_admin()  with the following::

function DisplayListOfPosts_admin() {

global $wpdb; //wpdb wordpress database class
$mytestdata=$wpdb->get_results(“select ID,post_title from $wpdb->posts”); //get a query into wpdb class
echo “<br>Display list of posts:<br>”;

echo “<table border=1>”;//display the results as a table

foreach ($mytestdata as $singleraw) //loop inside the query
{
echo “<tr>”;
echo “<td>”.$singleraw->post_title.”</td>”;
echo “<td>”.$singleraw->ID.”</td>”;
echo “</tr>”;
}

echo “</table>”;

}

images (6)

 

Step 08: Final code:

<?php

/*
Plugin Name: Display List of Posts
Plugin URI: http://www.flash-jet.com
Description: A plugin demo that will display list of Posts
Version: 1.0
Author: Gabriel Magen
Author URI: http://www.flash-jet.com
*/

add_action(‘admin_menu’,’DisplayListOfPosts_admin_actions’);

function DisplayListOfPosts_admin_actions() {

add_options_page(‘Display List of Posts’,’Display List of Posts’,’manage_options’,__FILE__,’DisplayListOfPosts_admin’);
}

function DisplayListOfPosts_admin() {

global $wpdb;
$mytestdata=$wpdb->get_results(“select ID,post_title from $wpdb->posts”);
echo “<br>Display list of posts:<br>”;

echo “<table border=1>”;
foreach ($mytestdata as $singleraw)
{
echo “<tr>”;
echo “<td>”.$singleraw->post_title.”</td>”;
echo “<td>”.$singleraw->ID.”</td>”;
echo “</tr>”;
}
echo “</table>”;

}
?>

Based on:

Learn how to develop WordPress Plugins

01  – Under <Wordpress-directory>wp-contentPlugins create a directory with the Plugin Name.

02 – There create a file <Plugin Name>.php

03 – Under WordPress plugins page the new plugin will be shown.

04 – Copy and paste the HelloWorld example below to <Plugin Name>.php file.

05 – Activate the Plugin from Plugins page.

06 – Your first plugin runs and displays “Hello World” at the top of WordPress admin area.

Example 1 - Hello World:
<?php
/**
* Plugin Name: HelloWorld
* Plugin URI: http://www.flash-jet.com
* Description: HelloWorld Example
* Version: 1.5
* Author: Gabriel Magen
* Author URI: http://www.flash-jet.com
* License: A "Slug" license name e.g. GPL12
**/

function hello_world()
{ 
    echo '<hr><b><center>Hello World !!!!!!!<hr>'; 
}

add_action("admin_head","hello_world");
?>

Read more about plugin development here: https://developer.wordpress.org/