Total Pageviews

Friday, February 3, 2012

How to add administration menus in wordpress


This article explains how plugin authors can add administration menus.

Using Wrapper Functions

Since most sub-level menus belong under the Settings, Tools, or Appearance menus, WordPress supplies wrapper functions that make adding a sub-level menu items to those top-level menus easier. Note that the function names may not match the names seen in the admin UI as they have changed over time:

Dashboard
<?php add_dashboard_page( $page_title, $menu_title, $capability, $menu_slug, $function); ?>


Posts
<?php add_posts_page( $page_title, $menu_title, $capability, $menu_slug, $function); ?>


Media
<?php add_media_page( $page_title, $menu_title, $capability, $menu_slug, $function); ?>


Links
<?php add_links_page( $page_title, $menu_title, $capability, $menu_slug, $function); ?>


Pages
<?php add_pages_page( $page_title, $menu_title, $capability, $menu_slug, $function); ?>


Comments
<?php add_comments_page( $page_title, $menu_title, $capability, $menu_slug, $function); ?>


Appearance
<?php add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function); ?>


Plugins
<?php add_plugins_page( $page_title, $menu_title, $capability, $menu_slug, $function); ?>


Users
<?php add_users_page( $page_title, $menu_title, $capability, $menu_slug, $function); ?>


Tools
<?php add_management_page( $page_title, $menu_title, $capability, $menu_slug, $function); ?>


Settings
<?php add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function); ?>

More:Here is an example of a WordPress plugin that inserts new menus into various places:
 Administration_Menus

Tuesday, January 31, 2012

Category Posts

<?php
/*
Template Name: Category Posts
*/
get_header();
?>

        <div id="content-container">
            <div id="content" role="main">
<?php
//get all terms (e.g. categories or post tags), then display all posts in each term
$taxonomy = 'category';//  e.g. post_tag, category
$param_type = 'category__in'; //  e.g. tag__in, category__in
$term_args=array(
 'orderby' => 'name',
 'order' => 'ASC'
);
$terms = get_terms($taxonomy,$term_args);
if ($terms) {
 foreach( $terms as $term ) {
   $args=array(
     "$param_type" => array($term->term_id),
     'post_type' => 'post',
     'post_status' => 'publish',
     'posts_per_page' => -1,
     'caller_get_posts'=> 1
     );
   $my_query = null;
   $my_query = new WP_Query($args);
   if( $my_query->have_posts() ) {
     echo '<h2>List of Posts in '.$taxonomy .' '.$term->name.'</h2>';
     while ($my_query->have_posts()) : $my_query->the_post(); ?>
     <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    <?php if ( is_front_page() ) { ?>
                        <h2 class="entry-title"><?php the_title(); ?></h2>
                    <?php } else { ?>
                        <h1 class="entry-title"><?php the_title(); ?></h1>
                    <?php } ?>

                    <div class="entry-content">
                        <?php //the_content();
                        the_excerpt();
                        the_post_thumbnail(); ?>
                    </div><!-- .entry-content -->
                </div>
      
<?php

           endwhile;
   }
 }
}
wp_reset_query();  // Restore global post data stomped by the_post().
?>

            </div><!-- #content -->
        </div><!-- #content-container -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Friday, January 27, 2012

Category Posts Widget

Adds a widget that shows the most recent posts in a single category.

Category Posts Widget is a light widget designed to do one thing and do it well: display the most recent posts from a certain category.

Category Posts Widget

Tuesday, January 24, 2012

PHP array functions

PHP array  samples
 1) Desplaing the array in order, with out using sort functions
<?php
$array=array(1,20,5,16,7,19,3);
$cnt = count($array) - 1;
$FinalTemp = array();
for ($i = 0; $i <= $cnt; $i++) {
foreach($array as $key=>$value)
{
     if($value==max($array))
 {
  $sort[] = max($array);
  unset($array[$key]);
  }
}
}
 print_r($sort);
?>

2) In the main array, First delete one array values and then add other array values to the main array.
<?php
$array=array(5,4,5,7,3,6,4,1,8,4,5,6,2,1);
$delete=array(4,5,6);
$add=array(11,12,12,18);

foreach($array as $k=>$val)
{
if(in_array($val, $delete))
{
unset($array[$k]);
}
}
$result = array_merge((array)$array, (array)$add);
arsort($result);
print_r($result);
?>


3) array_count_values — Counts all the values of an array

<?php
$arr=array(a,c,k,n,n,h,r,a,a,a,c,h,b,h,k,n);
print_r(array_count_values($arr));
?>

Back to Top Scroll Up

The following Javascript will go to top of the page, when the link is clicked.
// JavaScript Document

var up_timer

function getPosition(){
yoko = document.body.scrollLeft || document.documentElement.scrollLeft;
tate = document.body.scrollTop  || document.documentElement.scrollTop;

}

function pageup(x,y){
if(up_timer) clearTimeout(up_timer);
if(y >= 1){
getPosition();
var divisionY = (tate-(tate/5));
var Y = Math.floor(divisionY);
window.scrollTo(yoko,Y);
up_timer = setTimeout("pageup("+yoko+","+Y+")",2);
}else{
window.scrollTo(yoko,0);
clearTimeout(up_timer);
}
}

function scrollup(){
getPosition();
pageup(yoko,tate)
}

Saturday, January 21, 2012

Simple rewriting using .htaccess


All requests to whatever.htm will be sent to whatever.php:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.htm$ $1.php [NC]

The [NC] part at the end means "No Case", or "Case-Insensitive".
Requests to the .html automatically rewrite to .php. 
Ex: If it is whatever.htm or whatever.php, but they always get whatever.php in the browser, and this works even if whatever.htm doesn't exist!

Sunday, January 15, 2012

BLOG SPOT GET BLOG NOTES HTML WORDPRESS PHP DRUPAL CODEIGNITER

BLOG SPOT GET BLOG NOTES  HTML WORDPRESS  PHP DRUPAL CODEIGNITER
get-blognotes: Useful Coding Tools HTML,  PHP, WordPress, Drupal, Codeigniter, and JavaScript Libraries For Web Developers .
  http://get-blognotes.blogspot.in/