An introduction to new php 7 book

php 7

php 7


I had started writing a well documented book on PHP 7 in the month of March but I’d to leave the project unfinished as situation demanded.
I’m eager to go back to my unfinished job. Before that I thought it would be good for my readers to give them a glimpse of how I had started it.

Note from Author

I always love to write for the beginners. I love the innocent moments of bringing few new things to my dearest readers. And this time I’ve done it by taking a completely different approach. You build web applications and learn php 7 simultaneously.
Continue reading “An introduction to new php 7 book”

how to become a good wordpress developer

It’s not at all difficult to become a good wordpress developer.

Wordpress developer

WordPress developer


People often make a bad mistake. They think WordPress is only a simple, user friendly blog-engine. They use WordPress as a blogger not as a web programmer. There must be some misunderstanding or a set of thinking-patterns that is actually a wrong action attributable to bad judgment. If you want to become a good wordpress developer, you mustn’t make this mistake.
Continue reading “how to become a good wordpress developer”

How to become a good PHP developer

I want to answer this question from a beginner’s perspective. You’re reading this article because you’re a PHP developer with little knowledge and you want to make ‘coding as your forte’.

php developer

php developer

Closed or Open?

I’ve seen two sides of server side scripting. I had started learning PHP and MySQL much before I tried coding in C# and ASP.NET. I had not been developing with ASP.NET for long because I’d to leave it. Was it destiny? Actually I didn’t like the closed source. That was the real reason. Besides it was not my profession. I was not a professional PHP developer at the beginning. I was a data-journalist who wanted to be an Author and Ethical Hacker.
Continue reading “How to become a good PHP developer”

Source of Inspiration

Good Writings: Source of Inspiration

Good writings always inspire us. It remains a good source of inspiration. How does it remain a source of inspiration? I cannot explain the internal mechanism but it works just like songs or paintings or anything good in this life. Good writings, interesting articles or books are not something that you find always. It’s a kind of good discovery!
Continue reading “Source of Inspiration”

Good technology and bad addiction

Technology is not bad. bad is the situation when we get addicted to it. Here, in this article I just wanted to touch the tip of the iceberg. You probably know the amount of danger is how humongous.

Good technology may grow addiction too

Can technology be really bad? May be some technology has some bad effect. Here is an example.
train, flight, taxi and a cycle//embedr.flickr.com/assets/client-code.js
I took this photo of the old man on the roadside at Puri. He was busy checking his smart-phone stopping his bicycle. May be it was an emergency but this is not a good habit to check your mobile on a busy roadside.

There are risks, and you know it!

No doubt in it. While checking smart-phone on the road-side you may invite trouble. For that reason only can we conclude, smart-phone technology is bad? No, certainly not.

Then What do you want to say?

I’m trying to say about the bad side effect of technology. And in that sense, some risks we can easily avoid. We need not install unnecessary software in our PC and phones.
Reading this will make views much clearer.
Technology Addiction
Any addiction is bad. Technology makes it, sometimes, worse.
So give it a second thought. The following link is so pathetic.
Chinese teen dies at Internet addiction rehab camp

Read The snippets

China is investigating the death of a teenager who was allegedly beaten to death in a camp designed to treat Internet addiction, state media said.

Deng Senshan, 15, died Sunday, less than a day after his parents sent him to the camp in southern Guangxi province, Xinhua News Agency reported.

This is truly alarming

Half of all teens are feeling addicted to their mobile devices, and 28 percent of them say their parents are addicted too. This is really scary. Where we are heading towards?
Half Of Teens Say They Feel Addicted To Their Devices
If this trend persists, the time has come to think over it. We need to bring this topic on the public forum as much as possible and start campaigning about it in the grass root level.

Digital switch off

make it mandatory that we should switch off our mobiles, tabs and PCs for a certain period of time. Let’s make it mandatory for our mental and physical health. Interaction with human beings is extremely important. We should consider to enhance that also.

How I joined multiple Bootstrap themes with my official WordPress site

I thought I should write down this without delay and share with my readers. These are bits and pieces of my experiences of writing my official website sanjibsinha.com. It was a kind of trial and error method that I had always expected that, well – touch wood, it’d survive somehow.
And it survived the experiments. Google started indexing it and I think the time has also come to play with Google analytic.
Let me finish it very fast and start from the very beginning.
I decided to inject multiple bootstrap CSS styling in my website. It’s a kind of bootstrapping wordpress.
As you know, when you start building a wordpress site from scratch you need few files at the very beginning. They are – style.css and few more PHP files like index, page, home, header, footer, sidebar etc.
I decided to make the front page a static page so I injected a ‘front-page.php’ file in that beginning procedure.
As of now I am keeping three styles – two of them are open source bootstrap theme and the other one is the mystery (please download it from my github repository).
The first step is – make your default style intact so that it does not break.
My ‘style.css’ code:
@import url('css/font-awesome.min.css');
@import url('css/bootstrap.min.css');
@import url('css/animate.css');
@import url('css/style.css');

body {

}

Next get the link in the ‘header.php’ file:

bloginfo('stylesheet_url');

I don’t want the ‘Home’ navigation in my first page menu bar so just excluded it with a simple code:
wp_list_pages(array('title_li' => '', 'exclude' => 4));
Remember wordpress keeps everything as ‘post’ inside database. My home page post id is 4 and I’m excluding it from the first page navigation.
You know the other wordpress pages more or less follow this same logic:

if ( have_posts() ) : while ( have_posts() ) : the_post();
I decide to get the permalink, time, title, and content after that so the functions are easy:
the_permalink();
the_title();
the_time('l, F jS, Y'); //you can change the format, please search in the codex
the_content()

You should also keep an error message if something goes wrong with your code.
_e('Sorry, there are no posts.');
As I said before: there are three themes as of now. So I need two more template files. One is for Blog and the other, the custom one is for any other purposes.
You need ‘header-blog’, ‘footer-blog’, ‘header-custom’, and ‘footer-custom’. And in the related template file don’t forget to write like this:
get_header('blog')
get_header('custom')

Besides these simple routine I decided to show one category in my custom styling. I’ll write this part in detail.
Finally my website looks like this:

The Home page:

The blog Page:

The Contact page:

The archive page:

And finally I decided to show my ‘PHP’ category posts in the custom styling:

So this is it. For full code please visit my Github repository:

GITHUB

What facebook knows about you?

I’m currently working with facebook developers tools. Trying to merge with WordPress or any other PHP application that comes my way.
In fact reactivating my account was a part of that process.
What I’ve found so far is astounding. The facebook privacy policy is disastrous. General people know very little about it but facebook knows a lot about them.
I’ll keep this post updated so if you’re worried about losing your privacy to billions of people, you may stay in touch.

Custom Post Type in WordPress for PHP Developers

Sometimes you need a custom post type in your WordPress application.
Let me explain why you need it first?
Wordpress comes up with two basic types of Posts. One is Post and the other is Page. People often get misguided and think WordPress is just a blog engine and a content management system on a PHP platform.
This concept is wrong.
Wordpress is a sleeping giant whom you need to poke and tweak to get things done on your whim. Just make it talk, it’ll actually sing! Such is the power of WordPress.
In default Pages or Posts you may add plenty of contents and you can also categorize them, no problem.
But a custom post type is the symbol of your freedom. You’re going to do something with it that simple Page and Post could not do. You can extend your Custom Post Type to eternity. Unthinkable and unbelievable are the possibilities.
The process is extremely simple.
Add this code to your ‘functions.php’:

// ADD CUSTOM POST TYPE
add_action('init', 'create_post_type');
function create_post_type() {
    
    register_post_type('custom-content',
            array(
                'labels' => array(
                    'name' => __('Custom Content'),
                    'singular_name' => __('Custom Content')
                ),
                'public' => TRUE,
                'has_archive' => true
            ));
    
}

On the left side of your Admin Dashboard panel you get it. Just click and it’ll open. Now you can add any type of content here. Text, Image and Video.
Want to show it on your Home page?
Very simple. On the ‘front-page.php’ add this code:


$args = array( 'post_type' => 'generic-content', 'posts_per_page' => 10 );
$the_query = new WP_Query( $args ); 
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
the_title(); 
the_content(); 
wp_reset_postdata();  
endwhile; else:
_e( 'Sorry, no posts matched your criteria.' );
endif;

Besides on your front page you want to show the Custom content on a dedicated page. Create a ‘single-custom-content.php’ page and just paste the code of your ‘page.php’. You need to get the title and content, so it’s not difficult at all.

Why WordPress for PHP Developers?

For PHP developers who want to create applications quickly but efficiently, WordPress is the best choice.
I had worked with other PHP frameworks like Laravel and Codeigniter before and found them extremely time consuming. I tasted Drupal also.

In web development you ultimately handle with content or data. And this volume of data is becoming enormous with the passage of time. It has many titles, categories, sub-categories, sub-sub-categories and you may dig deeper.

This is big data.

The simplicity of WordPress makes this job absolutely fun with little coding. If you love to code then there is Laravel. You’ll have plenty of chances to code but it’ll take time.

An application that takes one month to be formed in Laravel, may take less than one week in WordPress.

I give you a very simple example.

It took less than one hour to build a full fledged web application with WordPress where I used four different themes. I just Bootstrapped them. look at the pages first!

The first one is Home page.

why wordpress

why wordpress

The second one is a Sample Page.

why wordpress

why wordpress

The Third one is a Generic content (Here your choice is simply endless)

why wordpress

why wordpress

And Lastly for any news oriented posts I chose a completely different styling with a sidebar where I can add any widgets any time.

why wordpress

why wordpress

You just cannot imagine how simple the total operation was! It took less than one hour with few WordPress functions like this:

get_header(); get_footer(); get_sidebar(); bloginfo('stylesheet_url'); wp_list_pages(array('title_li' => '', 'exclude' => 4));


May be I’m missing one or two functions. But It’s true that it really does not take much. For getting contents on your page or post, the main WordPress functions you need are also very simple.
They are like this:

if ( have_posts() ) : while ( have_posts() ) : the_post();
the_permalink(); the_title(); the_time('l, F jS, Y'); the_content(); 
endwhile; else:
_e('Sorry, there are no posts.');
endif;

The ‘functions.php’ file is little bit longer, but less than any PHP framework single page code!


// ADD CUSTOM POST TYPE
add_action('init', 'create_post_type');
function create_post_type() {

register_post_type('generic-content',
array(
'labels' => array(
'name' => __('Generic Content'),
'singular_name' => __('Generic Content')
),
'public' => TRUE,
'has_archive' => true
));

}

function post_movie_scripts() {

if(is_post_type_archive('movies')){

wp_enqueue_style('customstyle', get_template_directory_uri(). '/custom/custom-style.css', 'style');

}

}
add_action( 'wp_enqueue_scripts', 'post_movie_scripts' );

function startboot_scripts() {

wp_register_script('my_amazing_script', get_template_directory_uri() . '/startboot/vendor/jquery/jquery.min.js', array('jquery'), true);
wp_register_script('my_amazing_script', get_template_directory_uri() . '/startboot/vendor/bootstrap/js/bootstrap.min.js', array('jquery'), true);

wp_register_script('my_amazing_script', get_template_directory_uri() . '/startboot/vendor/scrollreveal/scrollreveal.min.js', array('jquery'), true);
wp_register_script('my_amazing_script', get_template_directory_uri() . '/startboot/js/creative.min.js', array('jquery'), true);

wp_register_script('min', get_template_directory_uri() . '/custom/lib/jquery/jquery.min.js', array('jquery'), true);
wp_register_script('bootstrap', get_template_directory_uri() . '/custom/lib/bootstrap/js/bootstrap.min.js', array('jquery'), true);

wp_register_script('new-age', get_template_directory_uri() . '/custom/js/new-age.min.js', array('jquery'), true);

wp_enqueue_script('startboot_script');

//wp_enqueue_style('news', get_template_directory_uri(). '/blog/blog-style.css', 'style');

if (is_page(4)) {

wp_enqueue_style( get_template_directory_uri(). '/style.css', 'style' );

}

elseif (is_page(array(2))) {

wp_enqueue_style('customstyle', get_template_directory_uri(). '/custom/custom-style.css', 'style');

}

elseif (is_page(7)) {

wp_enqueue_style('customstyle', get_template_directory_uri(). '/custom/custom-style.css', 'style');

}

/*
elseif (is_page(array(14))) {

wp_enqueue_style('animate', get_template_directory_uri(). '/hydrogen/css/animate.css', 'style');
wp_enqueue_style('icommon', get_template_directory_uri(). '/hydrogen/css/icomoon.css', 'style');
wp_enqueue_style('magnific', get_template_directory_uri(). '/hydrogen/css/magnific-popup.css', 'style');
wp_enqueue_style('salvattore', get_template_directory_uri(). '/hydrogen/css/salvattore.css', 'style');
wp_enqueue_style('style', get_template_directory_uri(). '/hydrogen/css/style.css', 'style');

}
*/
else {

//wp_enqueue_style('customstyle', get_template_directory_uri(). '/custom/custom-style.css', 'style');

wp_enqueue_style('news', get_template_directory_uri(). '/blog/blog-style.css', 'style');
}
}

add_action( 'wp_enqueue_scripts', 'startboot_scripts' );

function boot_scripts() {

if (is_page(16)) {

wp_enqueue_style('WP Bootstrap', get_template_directory_uri(). '/bootstrap/boot-style.css', 'style');

}

}
add_action( 'wp_enqueue_scripts', 'boot_scripts' );

if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '',
'after_widget' => '',
'before_title' => '

',
'after_title' => '

',
));

register_taxonomy( 'sample-taxonomy', 'post', array( 'label' => 'Sample Taxonomy'));

Look at the main ‘style.css’ code, this is unbelievable:

@import url('startboot/vendor/bootstrap/css/bootstrap.min.css');
@import url('startboot/vendor/font-awesome/css/font-awesome.min.css');
@import url('startboot/vendor/magnific-popup/magnific-popup.css');
@import url('startboot/css/creative.min.css');

body {

}

.home-content {

margin: 10px;
padding: 10px;

}

.footer-content {

}

The Other related style-sheet coding are equally simple and elegant.

I hope this post will help PHP developers to decide which they really need to work faster to give more output in less time.

I know your job is demanding.

WordPress Coding from Scratch

I just want to share my wordpress coding exercises with my readers.

The very first in this series is “wordpress coding from scratch”. It will teach you how to start your own wordpress theme from the scratch with minimum coding.

You need to create a theme folder in the “wp-content/theme” folder.

Suppose we name it “my-theme”.
In that folder you create a ‘style.css’ file and write few lines of code that can just start your first wordpress site.
Continue reading “WordPress Coding from Scratch”