Sunday, July 12, 2015

Wordpress Create article with Multiple categories,country,regions etc.

<?php
register_post_type('Article', array(
'labels' => array(
'name' => 'Articles',
'singular_name' => 'Article',
'add_new' => __( 'Add New' ),
'add_new_item' => __( 'Add new Article' ),
'view_item' => 'View Article',
'edit_item' => 'Edit Article',
   'new_item' => __('New Article'),
   'view_item' => __('View Article'),
   'search_items' => __('Search Article'),
   'not_found' =>  __('No Article found'),
   'not_found_in_trash' => __('No Article found in Trash'),
),
'public' => true,
'exclude_from_search' => false,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'_edit_link' =>  'post.php?post=%d',
'rewrite' => array(
"slug" => "article",
"with_front" => false,
),
'query_var' => true,
'supports' => array('title', 'editor', 'page-attributes'),
'menu_position' => 101
));

//Categories
register_taxonomy(
    'categories',
    array('article'),
        array(
        'hierarchical' => true,
        'labels' => array(
        'name' => _x( 'Categories', 'taxonomy general name' ),
        'singular_name' => _x( 'Category', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Category' ),
        'all_items' => __( 'All Categories' ),
        'parent_item' => __( 'Parent Category' ),
        'parent_item_colon' => __( 'Parent Category:' ),
        'edit_item' => __( 'Edit Category' ),
        'update_item' => __( 'Update Category' ),
        'add_new_item' => __( 'Add New Category' ),
        'new_item_name' => __( 'New Category Name' ),
        'menu_name' => __( 'Category' ),
    ),
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array(
"slug" => "category",
"with_front" => false,
),
));

//Countries
register_taxonomy(
    'country',
    array('article'),
        array(
        'hierarchical' => true,
        'labels' => array(
        'name' => _x( 'Countries', 'taxonomy general name' ),
        'singular_name' => _x( 'Country', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Countries' ),
        'all_items' => __( 'All Countries' ),
        'parent_item' => __( 'Parent Country' ),
        'parent_item_colon' => __( 'Parent Country:' ),
        'edit_item' => __( 'Edit Country' ),
        'update_item' => __( 'Update Country' ),
        'add_new_item' => __( 'Add New Country' ),
        'new_item_name' => __( 'New Country Name' ),
        'menu_name' => __( 'Countries' ),
    ),
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array(
"slug" => "country",
"with_front" => false,
),
));

//Regions
register_taxonomy(
    'region',
    array('article'),
        array(
        'hierarchical' => true,
        'labels' => array(
        'name' => _x( 'Regions', 'taxonomy general name' ),
        'singular_name' => _x( 'Region', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Regions' ),
        'all_items' => __( 'All Regions' ),
        'parent_item' => __( 'Parent Region' ),
        'parent_item_colon' => __( 'Parent Region:' ),
        'edit_item' => __( 'Edit Region' ),
        'update_item' => __( 'Update Region' ),
        'add_new_item' => __( 'Add New Region' ),
        'new_item_name' => __( 'New Region Name' ),
        'menu_name' => __( 'Regions' ),
    ),
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array(
"slug" => "region",
"with_front" => false,
),
));
?>

Wordpress create menu and submenu on admin side.

function admin_left_panel() {
    add_menu_page('Page Title', 'Left menu label', 'manage_options','pageurl1', 'menu_one');
    add_submenu_page('pageurl1', 'Page Title','Left menu label 2', 'manage_options', 'pageurl2','menu_two');
    add_submenu_page('pageurl1', 'Page Title','Left menu label 3','manage_options', 'pageurl3', 'menu_three');
}

add_action('admin_menu', 'admin_left_panel');

function menu_one() {
    echo '<div class="wrap"><div id="icon-options-general" class="icon32"><br></div><h2>Page 1</h2></div>';
}

function menu_two() {
    echo '<div class="wrap"><div id="icon-options-general" class="icon32"><br></div><h2>Page 2</h2></div>';
}

function menu_three() {
    echo '<div class="wrap"><div id="icon-options-general" class="icon32"><br></div><h2>Page 3</h2></div>';
}

Sunday, July 5, 2015

Wordpress custom query

<?php
$args_fp = array(
    'post_type' => 'page',
    'post__in' => array(10,11,12,13),
    'orderby' => 'post__in',
);
$fp_query = null;
$fp_query = new WP_Query($args_fp);
while ($fp_query->have_posts()) : $fp_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?><?php the_content(); ?></a></li>
<?php endwhile; ?>
?>