Thursday, May 14, 2015

Working with Google Analytics

Google offer a lot of services, Google Analytics (is look a bit similar to GWT service) is a premium website analytic service that help you examine a lot of something on your web carefully tracks and reports online website traffic is a tool for search engine optimization (SEO) and marketing puroses. it is a web paralytics services that the most world wide used. it is free for someone who is sign in with google account Gmail.
under accessing google account you visit www.google.com/analytics, the top right button click Access Google Analytics or Create an account. and then Set up a property (following the instruction from in order to set up web tracking code or tracking id put on your website or blog.
 

Google Webmaster Tools ( GWT )

Google Webmaster Tools ( GWT ) is the most important part of google to connect to webmasters and it is a tool help you to recognize the problems with your website in correctly and tell you about malware and help you to undersand what happen on your website.
The first thing to do you is you must log into google account ( gmail ) and than start add your website. after add site GWT recommend you to verify your owner site. there are 5 ways to verification.
example one easy way. you choose Alternate methods and choose HTML tage and then copy meta code html to passe on header of you website finally click VERIFY.
The next thing you should do is submitting xml file. on your website should have an xml file for submit to google for making easy to google index your site. in order to submit this file you make sour your website have a less on sitemap sitemap.xml (ex:www.yourwebsite.com/sitemap.xml) Wordpress you can generated it by plugin. the next go to menu Clawl and choose Sitemaps and then click bottom ADD/TEST SITEMAP and pass your file url and submit.
*** sitemap of blogger you just pass url:  /atom.xml?redirect=false&start-index=1&max-results=500

Saturday, April 4, 2015

About Wordpress

In 2003 wordpress has been start with a single bit code to enhance the typography of all writing and with not much user and you can count  on your fingers and toes. after that wordpress grown to a biggest self hosted blogging tool in the world wide that millions of website is used and tens of millions of people every day.
All things of document was created by and for the community that is an open source software code, that means there are hundreds of user around the word working on wordpress. it also free to use for anything from your without paying anyone a license fee and freedoms.
this software started as just a blogging system but used as a full CMS ( Content Management System) and so much thousands of themes, widgets and plugins.
you can download and install a software of wordpress on www.wordpress.org.

Relate post: Create post object

Friday, April 3, 2015

Create post object

In the WP_Post class is used to contain a lot of post objects stored by the database and is returned by functions like: get_post.
this is my example create post or page object:

<?php
// Create post object
$my_post = array(
  'post_title'    => 'My post',
  'post_content'  => 'This is my post.',
  'post_status'   => 'publish',
  'post_author'   => 1,
  'post_category' => array(8,39)
);

// Insert the post into the database
wp_insert_post( $my_post );


$post_id = wp_insert_post( $post, $wp_error );
//now you can use $post_id within add_post_meta or update_post_meta

$defaults = array(
  'post_status'           => 'draft',
  'post_type'             => 'post',
  'post_author'           => $user_ID,
  'ping_status'           => get_option('default_ping_status'),
  'post_parent'           => 0,
  'menu_order'            => 0,
  'to_ping'               =>  '',
  'pinged'                => '',
  'post_password'         => '',
  'guid'                  => '',
  'post_content_filtered' => '',
  'post_excerpt'          => '',
  'import_id'             => 0,
  'post_category' => array(5,7)
);

?>
<?php
// Add or Update the meta field in the database.
if ( ! update_post_meta (7, 'fruit', 'banana') ) {
add_post_meta(7, 'fruit', 'banana', true );
};
?>
<?php add_post_meta( 68, 'my_key', '47' ); ?>
<?php add_post_meta( 68, 'my_key', '682' ); ?>
<?php add_post_meta( 68, 'my_key', 'The quick, brown fox jumped over the lazy dog.' ); ?>

<?php
echo'<br>Insert post:'.get_option('default_ping_status');
$defaults = array(
  'post_title'      => 'Post Title',
  'post_content'  => 'This is post content',
  'post_status'           => 'publish',
  'post_type'             => 'listing',
  'post_author'           => 1,
  'ping_status'           => get_option('default_ping_status'),
  'post_parent'           => 0,
  'menu_order'            => 0,
  'to_ping'               =>  '',
  'pinged'                => '',
  'post_password'         => '',
  'guid'                  => '',
  'post_content_filtered' => '',
  'post_excerpt'          => '',
  'import_id'             => 0,
  'post_category' => array(5,7)
);
//$post_id = wp_insert_post( $defaults);
if($post_id){
echo'<br>inserted';
if ( ! update_post_meta ($post_id, 'fruit', 'banana') ) {
add_post_meta($post_id, 'fruit', 'banana', true );
echo'<br>mata inserted';
}
}
echo'<br>';
$catsql = "select * from $wpdb->terms c,$wpdb->term_taxonomy tt  where tt.term_id=c.term_id and tt.taxonomy='listingcategory' and c.name != 'Uncategorized' and c.name != 'Blog'  $substr order by c.name";
echo $catsql;
$term_taxonomy_ids = wp_set_object_terms(386, 5, 'listingcategory' );
 ** Do you know about PHP code Free and open source software (FOSS)?

Free and open-source software (FOSS)

Free and open-source software (FOSS) a type of software that you can be classified as both open-source software and free software.That is everyone is use, copy, study and change the software in other way with free licensed and the source code is openly shared so that they are encouraged to voluntarily improve the design of the it.In contrast to proprietary software, where the software is under restrictive copyright and the source code is usually hidden from the users.
The income of using Free and open source can include decreasing software price, increasing  stability (especially in regard tomalware) and security, protecting privacy, and make easy to users more control over their own hardware.Open source OS like Linux and descendents of BSD are widely utilized Nowadays, powering millions of desktops, servers, smartphones (e.g.Android), and other devices.  Open-source licenses and Free software licenses are used by many software packages.
 *** Working With Wordpress Administrator side

Working With Wordpress Administrator side

Atfer visit your domain name like www.yourdomainname.com/wp-admin and enter user and password you will see Administrator side of wordpress cms.
The Administration page allow you to control features many tool of your WordPress installation. that are: the toolbar (header of site), the navigation tool, the work area and footer of site
The Adminstrator sidebar, the Toolbar has links to various any functions of administration, and is showed at top of Administration side. All Toolbar tools expand (flyout) after you hovered over to display more information.
Left part of the site is the (main navigation) that is a menu showing each functions of the administrative you can process it. At the bottom of that side is a (Collapse menu) button that that is a menu into a set of icons, or to expands to list them by major function.Those function are Posts, the sub-menu expands (fly-out) when hovered over, and expands fully if an item clicked.
In the middle of the screen is the large area we call the work area. It showed  the specific information relating to a particular navigation choice, such as adding a new post, is presented and collected.
End, The footer, it stay at the bottom of  Administration site in light shading, are links to WordPress, thanking you for using it, with the current version of WordPress that you have used.

Toolbar of wordpress administration screens

On the top of administration screen wordpress enable and show you a bar call Toolbar that it consists of the info of this CMS as quick access to other function like poset, and new page, edit page or post, links, and new plugin, user information, show you the comments, alerts new version of wordpress plugings, themes and make you easy switch from admin site to home page site. you can enable or disable it by this way: make sour you stay log on and go to administration screen, after go to user and than your profile link of left menu and find Toolbar and "Check" Show Toolbar when viewing site.
finally update your profile.

WP_Admin_Bar is class of CMS WordPress use for generating the Toolbar when you signed in you can lines the top of WordPress sites. It can be hooked and modified to remove or add options that appear in the administration  bar.

How to using this class:

It is used internally by WP to create $wp_admin_bar that is a object of it . Most modifications to WordPress toolbar will generally be done by modifying the $wp_admin_bar object that is passed through the admin_bar_menu hook.
Example:

add_action( 'admin_bar_menu', 'modify_admin_bar' );

function modify_admin_bar( $wp_admin_bar ){
  // you put you option to show on bar hare ..... 
}

Array Session

Array Session

What is an Array?

Array is a variable that special , that can hold more than one or more value at a the same time.

If you have a the list of somethings (a list of animal names, for example), storing the animal in single variables could look like this:
$animal1 = "cow";
$anima2 = "cat";
$anima3 = "dog";

 See the Session functions of documentation for more information on how to this is used. An associative array is containing session variables available to the current script.

This Code testing Array Session in php.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php session_start(); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
if(isset($_POST['btnset'])){
$data_form[] = array(
"fname"  => $_POST['fname'],
"lname"  => $_POST['lname'],
"sex"  => $_POST['sex'],
"age"  => $_POST['age'],
"phone"  => $_POST['phone'],
"address"  => $_POST['address']
);
$_SESSION['form'] = $data_form;
}else if(isset($_POST['btnclear'])){
if(isset($_SESSION['form'])){
unset($_SESSION['form']);
}
}
function form_val(){
if(isset($_SESSION['form'])){
$usercart=$_SESSION['form'];
/*foreach ($usercart[0] as $key => $item)
        {
echo'<br>'.$usercart[0][$key];
}*/
return $usercart;
}else{
return false;
}
}
?>
<form method="post">
<?php $val=form_val(); ?>
fname<input type="text" name="fname" value="<?php echo $val[0]['fname'];?>"  />
lname<input type="text" name="lname" value="<?php echo $val[0]['lname'];?>" />
sex<input type="text" name="sex" value="<?php echo $val[0]['sex'];?>" />
age<input type="text" name="age" value="<?php echo $val[0]['sex'];?>" />
phone<input type="text" name="phone" value="<?php echo $val[0]['phone'];?>" />
address<input type="text" name="address" value="<?php echo $val[0]['address'];?>" />
<input type="submit" value="Set" name="btnset" />
</form>
<form method="post">
<input type="submit" value="Clear" name="btnclear" />
</form>
<form method="post">
<input type="submit" value="Other" name="ss" />
</form>



</body>
</html>



**** how to detect browser in php code

Detect browser in php code

This is PHP code to testing browser which is browser you are using or user access to:Firefox/Iceweasel, Opera, Mozilla (and other Gecko engine browsers) to MSIE, Netscape,Galeon, K-Meleon, Lynx, Safari/Chrome (and other WebKit engine browsers), KHTML / Konqueror, and Mac IE browsers like IE 5.1 and 5.2. This php code let's test together: 'Internet Explorer', '/firefox/i' => 'Firefox', '/safari/i' => 'Safari', '/chrome/i' => 'Chrome', '/opera/i' => 'Opera', '/netscape/i' => 'Netscape', '/maxthon/i' => 'Maxthon', '/konqueror/i' => 'Konqueror', '/mobile/i' => 'Handheld Browser' ); foreach ($browser_array as $regex => $value) { if (preg_match($regex, $user_agent)) { $browser = $value; } } return $browser; } function getOS() { global $user_agent; $os_platform = "Unknown OS Platform"; $os_array = array( '/windows nt 6.2/i' => 'Windows 8', '/windows nt 6.1/i' => 'Windows 7', '/windows nt 6.0/i' => 'Windows Vista', '/windows nt 5.2/i' => 'Windows Server 2003/XP x64', '/windows nt 5.1/i' => 'Windows XP', '/windows xp/i' => 'Windows XP', '/windows nt 5.0/i' => 'Windows 2000', '/windows me/i' => 'Windows ME', '/win98/i' => 'Windows 98', '/win95/i' => 'Windows 95', '/win16/i' => 'Windows 3.11', '/macintosh|mac os x/i' => 'Mac OS X', '/mac_powerpc/i' => 'Mac OS 9', '/linux/i' => 'Linux', '/ubuntu/i' => 'Ubuntu', '/iphone/i' => 'iPhone', '/ipod/i' => 'iPod', '/ipad/i' => 'iPad', '/android/i' => 'Android', '/blackberry/i' => 'BlackBerry', '/webos/i' => 'Mobile' ); foreach ($os_array as $regex => $value) { if (preg_match($regex, $user_agent)) { $os_platform = $value; } } return $os_platform; } $user_os = getOS(); $user_browser = getBrowser(); ?>



***** In WordPress  Create Slug and post page object