How to check not null value in php?

if (!($error == NULL))
Simply do:
if ($error)
One would think that the first is more clear, but it's actually more misleading. Here's why:
$error = null;

if (!($error == NULL)) {
    echo 'not null';
}
This works as expected. However, the next five values will have the same and (to many, unexpected) behavior:
$error = 0;
$error = array();
$error = false;
$error = '';
$error = 0.0;
The second conditional if ($error) makes it more clear that type casting is involved.
If the programmer wanted to require that the value actually be null, he should have used a strict comparison, i.e., if ($error !== null)

How to get theme directory in wordpress?

<?php echo  get_template_directory_uri(); ?>

How to force full width content in genisis?



// Add custom body class to the head
add_filter( 'body_class', 'add_body_class' );
function add_body_class( $classes ) {
$classes[] = 'agentpress-custom';
return $classes;
}

// Force full width page layout
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );


how to add some content along gensis loop?

//remove_action( 'genesis_loop', 'genesis_do_loop' );

add_action( 'genesis_loop', 'add_to_loop' );

function add_to_loop() {

query_posts('post_type=post&posts_per_page=10&orderby=date&order=desc');
while ( have_posts() ) : the_post();

echo '<div class="tcover" style="margin:13px;width:200px;">';
echo '<div class="tthumb" style="height:200px;background:url(';

if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), array(200, 200) );
echo  $large_image_url[0];
}

echo ');background-position:center;">';

echo '</div>';
echo '<div class="ttitle">';
the_title();
echo '</div>';
echo '</div>';
         
endwhile;

// Reset Query
wp_reset_query();

/* end */




// pages  that have content inside

while ( have_posts() ) : the_post();
get_template_part( 'content', 'page' );
comments_template( '', true );
endwhile;


}


genesis(); 

How to get image thumbnail url in wordpress

if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
$large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), array(200, 200) );
echo  $large_image_url[0];
}




you can just change the   array(200, 200)  to   array(400, 400)  something like that to get big image url links in wordpress

How to create a WordPress basic theme?


How to create a WordPress theme?

This tutorial will show you how to create a simple WordPress theme. When building your own theme, you can use our Free WordPress themes for reference.

How to create a basic WordPress theme?

To start building your theme, first create a sub-folder in the wp-content/themes directory in your WordPress folder. For the purpose of this tutorial, we will call the folder "tutorial_theme". The name of the folder should correspond to the name of the theme you want to create. To do this you can use either your favorite FTP client or the File Manager tool in your cPanel.
Before you start creating the theme, you should decide how the layout of your website will look like. In this tutorial we will build a WordPress theme that consist of a header, sidebar, content area and a footer ,as shown below:


To do this we will have to create the following files into the tutorial_theme directory:
  • header.php - This file will contain the code for the header section of the theme;
  • index.php - This is the main file for the theme. It will contain the code for the Main Area and will specify where the other files will be included;
  • sidebar.php - This file will contain the information about the sidebar;
  • footer.php - This file will handle your footer;
  • style.css - This file will handle the styling of your new theme;
You can either create those files locally with a simple text editor(like notepad for example) and upload them via FTP or you can use the File Manager tool in your cPanel to create the files directly on your hosting account.
Now let's take a closer look at each file and what it should contain:

The header.php file

In this file you should add the following code:
<html>
<head>
<title>Tutorial theme</title>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">
</head>
<body>
<div id="wrapper">
<div id="header">
<h1>HEADER</h1>
</div>
Basically, this is simple HTML code with a single line containing a php code and a standard WordPress function. In this file you can specify your meta tags such as the title of your website, meta description and the keywords for your page.
Right after the title the line we add
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">
tells WordPress to load the style.css file. It will handle the styling of your website.
The
<?php bloginfo('stylesheet_url'); ?>
part of the line is a WordPress function that actually loads the stylesheet file.
Next, we have added the beginning of a "div" with class wrapper which will be the main container of the website. We have set class for it so we can modify it via the style.css file.
After that we have added a simple label HEADER wrapped in a "div" with class "header" which will be later specified in the stylesheet file.

The index.php file

<?php get_header(); ?>
<div id="main">
<div id="content">
<h1>Main Area</h1>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<h4>Posted on <?php the_time('F jS, Y') ?></h4>
<p><?php the_content(__('(more...)')); ?></p>
<hr> <?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p><?php endif; ?>
</div>
<?php get_sidebar(); ?>
</div>
<div id="delimiter">
</div>
<?php get_footer(); ?>
The code in this file begins with
<?php get_header(); ?>
which will include the header.php file and the code in it in the main page. It uses an internal WordPress function to do this. We will explain this in details later in this tutorial. Then we have placed a Main Area text to indicate which section of your theme is displayed in this area.
The next few lines consist of a PHP code and standard WordPress functions. This code checks whether you have posts in your blog created through the WordPress administrative area and displays them.
Next, we include the sidebar.php file with this line
<?php get_sidebar(); ?>
In this file you can display your post categories, archives etc.
After this line, we insert an empty "div" that will separate the Main Area and the Sidebar from the footer.
Finally, we add one last line
<?php get_footer(); ?>
which will include the footer.php file in your page.

The sidebar.php file

In the sidebar.php we will add the following code:
<div id="sidebar">
<h2 ><?php _e('Categories'); ?></h2>
<ul >
<?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?>
</ul>
<h2 ><?php _e('Archives'); ?></h2>
<ul >
<?php wp_get_archives('type=monthly'); ?>
</ul>
</div>
In this file we use internal WordPress functions to display the Categories and Archives of posts. The WordPress function returns them as list items, therefore we have wrapped the actual functions in unsorted lists (the <ul> tags).

The footer.php file

You should add these lines to the footer.php file:
<div id="footer">
<h1>FOOTER</h1>
</div>
</div>
</body>
</html>
With this code we add a simple FOOTER lable. Instead of this code you can add links, additional text, the copyright information for your theme and additional objects.

The style.css file

Add the following lines to the style.css file:
body { text-align: center; }
#wrapper { display: block; border: 1px #a2a2a2 solid; width:90%; margin:0px auto; }
#header { border: 2px #a2a2a2 solid; }
#content { width: 75%; border: 2px #a2a2a2 solid; float: left; }
#sidebar { width: 23%; border: 2px #a2a2a2 solid; float: right; }
#delimiter { clear: both; }
#footer { border: 2px #a2a2a2 solid; }
.title { font-size: 11pt; font-family: verdana; font-weight: bold; }
This simple css file sets the basic looks of your theme. Those lines set the background of your page and surround the main parts of your site with borders for convenience.
At this point your website should look like this:


As we have previously mentioned, internal WordPress functions are often used in the code of the theme. You can take a look at the complete Function Reference at the official website of WordPress for more information about each function.
From now on you can modify the CSS file, add images, animations and other content to your theme in order to achieve the looks you want for your blog!

ctrl+s instead of submit

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(window).keydown(function(event) {
    if (!(event.which == 83 && event.ctrlKey) && !(event.which == 19)) return true;
    alert("Ctrl-S pressed");
    event.preventDefault();
    return false;
});
</script>


or other example for mac also including IE, FIrefox and Chrome is

// simply disables save event for chrome
$(window).keypress(function (event) {
    if (!(event.which == 115 && (navigator.platform.match("Mac") ? event.metaKey : event.ctrlKey)) && !(event.which == 19)) return true;
    event.preventDefault();
    return false;
});

// used to process the cmd+s and ctrl+s events
$(document).keydown(function (event) {
     if (event.which == 83 && (navigator.platform.match("Mac") ? event.metaKey : event.ctrlKey)) {
        event.preventDefault();
        save(event);
        return false;
     }
});

Power css to little modify twenty twelve theme

body .site,
footer[role="contentinfo"]
{
box-shadow:none;
margin:0px auto;
padding:0px;
width:100%;
max-width:1600px;
}

body
{
background:#000;
}

hgroup,
.nav-menu,
.wrapper,
#primary,
.site-info
{
margin:auto;
max-width:1024px;
padding:0px 10px;
}

.main-navigation ul.nav-menu, .main-navigation div.nav-menu > ul,
.site-content article
{
border:0px;
}

.main-navigation
{
border-top:1px solid #d7d7d7;
border-bottom:1px solid #d7d7d7;
}
#secondary
{
display:none;
}

How to add line numbers in textarea?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
   <head>
   <style type="text/css">
   #codeTextarea{
      width:500px;
      height:510px;
   }
   .textAreaWithLines{
      font-family:courier;      
      border:1px solid #F00;
      
   }
   .textAreaWithLines textarea,.textAreaWithLines div{
      border:0px;
      line-height:120%;
      font-size:12px;
   }
   .lineObj{
      color:red;
   }
   </style>
   
   <script type="text/javascript">
   
   var lineObjOffsetTop = 2;
   
   function createTextAreaWithLines(id)
   {
      var el = document.createElement('DIV');
      var ta = document.getElementById(id);
      ta.parentNode.insertBefore(el,ta);
      el.appendChild(ta);
      
      el.className='textAreaWithLines';
      el.style.width = (ta.offsetWidth + 30) + 'px';
      ta.style.position = 'absolute';
      ta.style.left = '30px';
      el.style.height = (ta.offsetHeight + 2) + 'px';
      el.style.overflow='hidden';
      el.style.position = 'relative';
      el.style.width = (ta.offsetWidth + 30) + 'px';
      var lineObj = document.createElement('DIV');
      lineObj.style.position = 'absolute';
      lineObj.style.top = lineObjOffsetTop + 'px';
      lineObj.style.left = '0px';
      lineObj.style.width = '27px';
      el.insertBefore(lineObj,ta);
      lineObj.style.textAlign = 'right';
      lineObj.className='lineObj';
      var string = '';
      for(var no=1;no<200;no++){
         if(string.length>0)string = string + '<br>';
         string = string + no;
      }
      
      ta.onkeydown = function() { positionLineObj(lineObj,ta); };
      ta.onmousedown = function() { positionLineObj(lineObj,ta); };
      ta.onscroll = function() { positionLineObj(lineObj,ta); };
      ta.onblur = function() { positionLineObj(lineObj,ta); };
      ta.onfocus = function() { positionLineObj(lineObj,ta); };
      ta.onmouseover = function() { positionLineObj(lineObj,ta); };
      lineObj.innerHTML = string;
      
   }
   
   function positionLineObj(obj,ta)
   {
      obj.style.top = (ta.scrollTop * -1 + lineObjOffsetTop) + 'px';   
   
      
   }
   
   </script>
   
   </head>   
   <body>
   <form>
   <textarea id="codeTextarea">
   
   
   </textarea>
   </form>
   <script type="text/javascript">
   createTextAreaWithLines('codeTextarea');
   </script>
   </body>
</html>

Textarea auto scroll to bottom

<script>

var textarea = document.getElementById('textarea_id');

textarea.scrollTop = textarea.scrollHeight

</script>

How to build a WordPress plugin

WordPress is the most popular blogging and CMS platform out there today. Part of what has made it so successful is its ability to be extended via plugins to perform any function you desire. Developing a plugin framework is really difficult, but WordPress has one of the best solutions I’ve seen to date. So how do you go about taking advantage of it and building your own plugin?
WordPress development is done in PHP, which makes it pretty accessible as developers generally know their way around the language. Building a plugin is just a matter of creating a basic file structure and using WordPress provided functions and event hooks to drive your application.

The File Structure

All it takes to create a plugin is a single PHP file, but common practice dictates that you house your plugin and its files within a directory. To begin, create a directory to hold your plugin and give it a name matching your plugin. Then, within that directory, create your main PHP file, again naming the file with the name of your plugin:
+ super-plugin     - super-plugin.php
If your plugin is going to require any images, javascript, css, or additional PHP files, you will house those within this directory as well:
+ super-plugin     + admin          - super-plugin-admin.php     + img          - icon.png     + js          - super-plugin.js - super-plugin.php - readme.txt
In this example, I’ve created 3 directories, admin, img, and js to hold my additional files. The super-plugin-admin.php file will be used to provide a web interface to my plugin on the WP backend which I’ll address in another post.
Finally, if you plan on hosting your plugin in the WordPress plugin directory, you’ll need to include a file named readme.txt at the root of the directory. The file should follow the format detailed in this readme.txt example.

Defining Your Plugin

Next, we need to define our plugin so that WP will recognize it and allow it to be installed, removed, and activated.
Open your main plugin file, super-plugin.php and add the following to the top of the file:
\<\?php /* Plugin Name: Name Of The Plugin Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates Description: A brief description of the Plugin. Version: The Plugin's Version Number, e.g.: 1.0 Author: Name Of The Plugin Author Author URI: http://URI_Of_The_Plugin_Author License: A "Slug" license name e.g. GPL2 */ ?>
 

Initializing your program
Replace each line with the data for your plugin. This will define your plugin details for WordPress. At a minimum you need the Plugin Name: field for the plugin to be recognized.
Now that WordPress knows about your plugin, it’s time to make it do something. This is accomplished by using hooks and predefined WordPress functions. A hook is an event listener that is trigger based on outside events occurring. If your program needs to perform any type of setup, such as database table creation, you can tap into the plugin activation hook like so:
//SETUP function super_plugin_install(){     //Do some installation work } register_activation_hook(__FILE__,'super_plugin_install');
Then, when a user activates your plugin, any function that has been registered with the activation hook will be executed.
You might also want to register some custom javascript that your plugin will need to operate. You can do this by using the add_action hook to piggyback on to another process. In this case, we’re going to listen for the wp_enqueue_scripts event to trigger and let WordPress know that we want in on the script party and to please execute our function as well.
//SCRIPTS function super_plugin_scripts(){     wp_register_script('super_plugin_script',plugin_dir_url( __FILE__ ).'js/super-plugin.js');     wp_enqueue_script('super_plugin_script'); } add_action('wp_enqueue_scripts','super_plugin_scripts');
When scripts are being loaded up, your function will get executed and your script will get registered and queued to be added into the head portion of the HTML.
Finally, you want to actually run your program. You can do this by listening to various WP hooks and waiting for an appropriate event that would trigger your code to run. If you want to run your program every time a visitor comes to your site, you can use the ‘init’ or ‘wp_loaded’ action to trigger your code:
//HOOKS add_action('init','super_plugin_init'); /********************************************************/ /* FUNCTIONS ********************************************************/ function super_plugin_init(){     //do work     run_sub_process(); } function run_sub_process(){     //more work }

In this example, the super_plugin_init() function will get called on every new request and you can perform whatever logic you need.