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_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>”;
}
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 */
this will call register_shortcodes function in the public folder of the plugin
public function register_shortcodes() {
add_shortcode( 'crud_links_operation', array( $this, 'shortcode_crud_links_operation' ) );
}
this will call shortcode_crud_links_operation that will generate html to display in the shortcode
after we create the shortcode we can insert it to a post or or page
[crud_links_operation][/crud_links_operation] and go to wp post and she the html you inserted in the short code.
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptRead More
Privacy & Cookies Policy
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.