Sunday, 31 May 2015

Show all categories in drop down wordpress

Hi Guys,

Hope you all doing good.

So here you'll found a wordpress function to create drop down of Categories in drop down


<form action="<?php bloginfo('url'); ?>/" method="get">
<?php
$select = wp_dropdown_categories('show_option_none=Select category&show_count=1&orderby=name&echo=0');
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select); echo $select; ?>
<noscript><input type="submit" value="View" /></noscript>
</form>

How to create Custom Post Type with Taxonomies

Hi Guys,

Hope you all doing good.

So here you'll found a wordpress function to create Custom Post Type with Taxonomies



/* Radio Post Type Section Start*/

add_action( 'init', 'radio' );
function radio() {
 
    $labels = array(
        'name'                 => _x('Radio  Interviews', 'post type general name'),
        'add_new'             => 'Add New Interview',
        'add_new_item'         => 'Add New Interview',
        'edit_item'         => __('Edit Interview'),
        'new_item'             => __('New Interview'),
        'all_items'         => __('All Interviews'),
        'view_item'         => __('View Interviews'),
        'search_items'         => __('Search Interview'),
        'not_found'         =>  __('Empty'),
        'not_found_in_trash'=> __('Empty Trash'),
        'parent_item_colon' => '',
        'menu_name'         => __('Radio Interviews')
    );

    $args = array(
        'labels'             => $labels,
        'public'             => true,
        'publicly_queryable'=> true,
        'exclude_from_search'=> true,
        'show_ui'             => true,
        'show_in_menu'         => true,
        'query_var'         => true,
        'rewrite'            => true,
        'capability_type'     => 'post',
        'has_archive'         => true,
        'hierarchical'        => false,
        'menu_position'     => NULL,
        'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'post-formats', 'custom-fields' ),
    );
 
    register_post_type("radio_interviews",$args);
}

/*Custom Taxonomies For Radio Interview Post Type*/


function programs_console_taxonomies() {

register_taxonomy('programs-console', 'radio_interviews', array(

// Hierarchical taxonomy (like categories)
'hierarchical' => true,
// This array of options controls the labels displayed in the WordPress Admin UI
'labels' => array(
'name' => _x( 'Programs Category', 'taxonomy general name' ),
'singular_name' => _x( 'Programs-Category', 'taxonomy singular name' ),
'search_items' =>  __( 'Search Programs-Categories' ),
'all_items' => __( 'All Programs-Categories' ),
'parent_item' => __( 'Parent Programs-Category' ),
'parent_item_colon' => __( 'Parent Programs-Category:' ),
'edit_item' => __( 'Edit Programs-Category' ),
'update_item' => __( 'Update Programs-Category' ),
'add_new_item' => __( 'Add New Programs-Category' ),
'new_item_name' => __( 'New Programs-Category Name' ),
'menu_name' => __( 'Programs Categories' ),
),

// Control the slugs used for this taxonomy
'rewrite' => array(
'slug' => 'programs-console', // This controls the base slug that will display before each term
'with_front' => false, // Don't display the category base before "/locations/"
'hierarchical' => false // This will allow URL's like "/locations/boston/cambridge/"
),
));
}
add_action( 'init', 'programs_console_taxonomies', 0 );


add_filter( 'manage_edit-programs_columns', 'my_edit_programs_columns' ) ;

function my_edit_programs_columns( $columns ) {

$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Movie' ),
'duration' => __( 'Duration' ),
'genre' => __( 'Genre' ),
'date' => __( 'Date' )
);

return $columns;
}

add_action( 'manage_programs_posts_custom_column', 'my_manage_programs_columns', 10, 2 );

function my_manage_programs_columns( $column, $post_id ) {
global $post;

switch( $column ) {


/* If displaying the 'genre' column. */
case 'genre' :

/* Get the genres for the post. */
$terms = get_the_terms( $post_id, 'programs-console' );

/* If terms were found. */
if ( !empty( $terms ) ) {

$out = array();

/* Loop through each term, linking to the 'edit posts' page for the specific term. */
foreach ( $terms as $term ) {
$out[] = sprintf( '<a href="%s">%s</a>',
esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'programs' => $term->slug ), 'edit.php' ) ),
esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, 'programs-console', 'display' ) )
);
}

/* Join the terms, separating them with a comma. */
echo join( ', ', $out );
}

/* If no terms were found, output a default message. */
else {
_e( 'No Genres' );
}

break;

/* Just break out of the switch statement for everything else. */
default :
break;
}
}

Saturday, 15 February 2014

Add Custom Logo in Wp-admin Screen via Snippet

Hi There,

Some time our clients want's own logo on admin panel login screen then there are bunch of plugins available now a days, wanna try some codex ??

Then use below listed Snippet!!


Add this code to your theme's functions.php

<?php
// CUSTOM ADMIN LOGIN HEADER LOGO

function my_custom_login_logo()
{
    echo '<style  type="text/css"> h1 a {  background-image:url(' . get_bloginfo('template_directory') . '/images/logo_admin.png)  !important; } </style>';
}
add_action('login_head',  'my_custom_login_logo');
?>

Above mentioned GREEN COLOR's code showing you path from theme's images folder you can append it as you want...

That's all!!

Happy Programing :-)

Activate Plugin Without Wordpress Admin Panel

Hi There,

Some time we have some restrictions in wordpress admin panel or some time wordpress's instillation  is not proper working and we are hurry to do some work.

So here is the best example you can use this example.

All you have to Add this code to your theme's function.php and there you have to mention plugin name and plugin's installation file.

<? php
function run_activate_plugin_noidex( $plugin ) {
    $current = get_option( 'active_plugins' );
    $plugin = plugin_basename( trim( $plugin ) );

    if ( !in_array( $plugin, $current ) ) {
        $current[] = $plugin;
        sort( $current );
        do_action( 'activate_plugin', trim( $plugin ) );
        update_option( 'active_plugins', $current );
        do_action( 'activate_' . trim( $plugin ) );
        do_action( 'activated_plugin', trim( $plugin) );
    }
    return null;
}
run_activate_plugin_noidex( 'ultimate-noindex-nofollow-tool-ii/ultimate-noindex.php' );
?>

So in above function I am taking an example to NO-INDEX, NO-FOLLOW plugin, you can see above GREEN COLOR line .

Here this is plugin folder "ultimate-noindex-nofollow-tool-ii" and this is installation file "ultimate-noindex.php"

You can use any plugin you want just replace the plugin name and installation file.

That's all!!

Happy Programing :-)