Showing posts with label Wordpress. Show all posts
Showing posts with label Wordpress. Show all posts

Sunday, 30 April 2017

View My Posts Alone - WordPress Plugin

Introduction


This is a WordPress Plugin which is used for the authors who write blogs in a Site. This can be mainly used for the Single Site Multi Author Concepts who does not want to share their writing with the others until it has been published. So for them this plugin can be very useful.

Plugin URL

  1. WordPress Plugin Repository: https://wordpress.org/plugins/view-my-posts-alone/ 
  2. GitHub Repository: https://github.com/Nareshkumar979/View-My-Posts-Alone

Plugin Description

  • This is a very simple and easiest of all the plugins. The View My Posts Alone plugin is specially designed for those who have many authors(contributors) or allow guest posts, custom user roles to access their blogs/articles. In WordPress, a contributor can write as much blogs and articles as they can and submit it and wait for review (i.e) to be published from the administrator or the Person who is in-charge of doing these things. But at the time when the contributor or the custom user role member visits the posts section or the custom post type he/she can see all the posts that has been presented in that site. If that happens there is no privacy for the contributors to write up their article and put up in the blog.
  • In order to overcome this type of problems alone this plugin has been written and it is very successful even for lots of users in that blog. It will restrict the posts or the CPT to view only the posts that has been published or which has been saved as draft by that user alone. It will never display other persons write ups onto the Dashboard of the Others.
  • The Administrator and the Blog Author can view all the posts that are being contributed to their site and confirm what are all the posts that can be published and what not to be published.
  • On the whole this will be fantastic for the Users who are onto the Blogging and make things secret from the other writers.

Sunday, 17 July 2016

Register a Custom Menus Location In WordPress

To register a custom Menu location you must use the following function for registration.

register_nav_menu( $location, $description );
$location - The location where you want to display the menu in your theme (e.g.) - Primary,Secondary,Main Header etc.,
$description - The Description about the menu Location and the Menu.

Step: 1 Add the following lines in the function.php file.
function register_menu() {
    register_nav_menu('primary-menu', __('Primary Menu'));
}
add_action('init', 'register_menu');

Step: 2 Add the following lines in the file where you want the menu to display.

if ( has_nav_menu( 'primary-menu' ) ) { /* if menu location 'primary-menu' exists then use custom menu */
      wp_nav_menu( array( 'theme_location' => 'primary-menu') );
}

Saturday, 16 July 2016

Register and Display a Sidebar in Wordpress

To register and display the Sidebar in WordPress you have to follow the two steps.

Step: 1 You have to add this in the Function.php file in your theme
Below the "wpb alone should be replaced by your theme name"

function wpb_widgets_init() {
    register_sidebar( array(
        'name' => __( 'Main Sidebar', 'wpb' ),
        'id' => 'sidebar-1',
        'description' => __( 'The main sidebar appears on the right on each page except the front page template', 'wpb' ),
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<h3 class="widget-title">',
        'after_title' => '</h3>',
    ) );
    register_sidebar( array(
        'name' =>__( 'Front page sidebar', 'wpb'),
        'id' => 'sidebar-2',
        'description' => __( 'Appears on the static front page template', 'wpb' ),
        'before_widget' => '<aside id="%1$s" class="widget %2$s">',
        'after_widget' => '</aside>',
        'before_title' => '<h3 class="widget-title">',
        'after_title' => '</h3>',
    ) );
    }
add_action( 'widgets_init', 'wpb_widgets_init' );

Step: 2 Display it Dynamically in the Page where ever you want by adding the below code

<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
    <div id="secondary" class="widget-area" role="complementary">
    <?php dynamic_sidebar( 'sidebar-1' ); ?>
    </div>
<?php endif; ?>

Note: " is_active_sidebar( 'sidebar-1' )" - The sidebar-1 is the id of the registered sidebar in the function.php file. If the id is not used properly the Sidebar will not be displayed even if the registration is correct.

Custom Post Type Loop in Wordpress

In order to get posts from our custom post type you can follow the loop that is shown below by replacing the post type with your custom post type.

$query = array(
        'post_type'=> 'your_custom_post_type',
        'orderby'    => 'ID',
        'post_status' => 'publish',
        'order'    => 'DESC',
        'posts_per_page' => -1
    );
    $result = new WP_Query( $query );
    if ( $result-> have_posts() ) : ?>
        <?php while ( $result->have_posts() ) : $result->the_post(); ?>
            <?php
            // to get the post featured image as thumbnail
            the_post_thumbnail('thumbnail');
             ?>
            <?php
           // to get the Post title
           the_title();
            ?>
            <?php
           // to get the post content
            the_content();
           ?>
        <?php endwhile; ?>
    <?php endif; wp_reset_postdata(); ?>

This query will get the posts that are created under your custom post type and i have displayed the post featured image, post title and the post content.

Sunday, 24 April 2016

Creating Custom Post type Plugin in Wordpress

8 Easy Steps of how to create a Custom Post type Plugin in WordPress

This post will provide you a very easiest way to create the custom post type plugin in WordPress which automatically creates your plugin with the default functionality that a WordPress plugin will have.

Plugin folder Structure:
  • wp-content
    • places_to_visit(folder-name)
    • index.php
      • css
        • style.css
      • js
        • jquery.js
      • images
        • logo.png

 Follow this Steps and you will find it Interesting of how easy the plugin creation is in WordPress.

Step:1 Create a New Folder inside the Plugins folder which you find it inside the wp-content.
Step:2 Name the New folder which you have created with the custom post-type plugins name that you are going to create.
Step:3 Open up your editor with a new file which you are using and paste the below code in that and save the file name as "index.php"

Index File Code:

<?php
/*
Plugin Name: Places to Visit
Plugin URI: http://nareshkumar979.blogspot.in/
Description: The plugin helps the tourists to know what are all the places available to visit when then plan to spend a vacation at a particular place.
Version: 1.0
Author: Naresh Kumar.P
Author URI: http://nareshkumar979.blogspot.in/
License: NK001
*/
//Starting of the Custom Post Type called "Places to Visit"
add_action( 'init', 'places_to_visit' );
function places_to_visit()
{
 $args = array(
            'labels' => array(
            'name' => 'Places to Visit',
            'singular_name' => 'Place to Visit',
            'add_new' => 'Add New',
            'add_new_item' => 'Add New Places to Visit',
            'edit' => 'Edit',
            'edit_item' => 'Edit Places to Visit',
            'new_item' => 'New Places to Visit',
            'view' => 'View',
            'view_item' => 'View Places to Visit',
            'search_items' => 'Search Places to Visit',
            'not_found' => 'No Places to Visit found',
            'not_found_in_trash' => 'No Places to Visit found in Trash',           
            ),          
            'menu_position' => 15,
            'supports' => array( 'title', 'editor', 'thumbnail', 'custom-fields' ),           
            'menu_icon' => plugins_url( 'images/logo.png', __FILE__ ),
            'public' => true         
         );
         register_post_type( 'places_to_visit',$args);            
 }
 //End of the Custom Post Type called "Places to Visit"
?>

Points to Ponder:

Note: The plugin Index file should not contain any spaces between the codes. It should be coded as per my "index.php" file.
"If index.php file is coded with spaces it will create warning dialog at the time of plugin activation"

In this plugin the post type will be "places_to_visit".
"supports"-> This will decide what are all functionalities and input fields that your plugin can have.
(eg.) I have added
  • title:  will hold the Post Name 
  • editor: used for entering the contents for that particular posts.
  • thumbnail:  used for having a image for the post.
  • custom-fields: It will be displayed if you create the custom fields for the posts that you create(Will explain in the Later posts of how to create custom fields for the particular posts)
For placing the Image icon to your plugin continue the steps below.

Step:4 Create a folder called "images" inside the custom post-type folder and place the image which you want to keep as icon for you plugin.
Note: the icon size should be either (24X24 or 32X32). Other than this size the icon will not fit in the menu place.
Step:5 For adding the css and js create seperate folder as you done for the images and include it in the pages which you need.
Step:6 At last after doing all this you go to the WordPress dashboard by logging in and move to the Plugins Menu.
Step:7 You will find the Name of the Plugin which you have created under the "Activate" mode.
Step:8 If you click on Activate your plugin will be activated and you will find your plugin in Sidebar Menu.


Email Code PHP

This is a Simple Code which is written in the PHP for Sending Emails from One Server to all the Other Domains. It is very easy and little C...