WordPress Template Hierarchy

<?php
/*
WordPress Template Hierarchy (as of WordPress 4.9)
is_404() -------------------------------------------------------------------------------------------------> 404.php
is_search() ----------------------------------------------------------------------------------------------> search.php
is_front_page() ------------------------------------------------------------------------------------------> front-page.php
is_home() ------------------------------------------------------------------------------------------------> home.php
is_attachment() ---------> {mime-type}.php -----------------> attachment.php ---------\
is_single() -------------> single-{post_type}-{slug}.php ---> single-{post_type}.php --> single.php -----\
is_page() ---------------> page-{slug}.php -----------------> page-{id}.php -----------> page.php --------> singular.php
is_post_type_archive() --> archive-{post_type}.php ----------------------------------------------------\
is_tax() ----------------> taxonomy-{tax}-{slug}.php -------> taxonomy-{tax}.php ------> taxonomy.php --\
is_category() -----------> category-{slug}.php -------------> category-{id}.php -------> category.php ---\
is_tag() ----------------> tag-{slug}.php ------------------> tag-{id}.php ------------> tag.php ---------> archive.php
is_author() -------------> author-{nicename}.php -----------> author-{id}.php ---------> author.php -----/
is_date() ---------------> date.php --------------------------------------------------------------------/
is_embed() --------------> embed-{post_type}-{format}.php --> embed-{post_type}.php ----------------------> embed.php
*/

Basic PHP

/*==================================
Basic Introduction of PHP
====================================*/
** PHP - Hypertext Preprocessor
** Server side scripting language
** First Released Date : 1994
** Created By: Rasmus Lerdorf
** Most CMS used PHP -
* WordPress
* Joomla
* Drupal
** Most popular website used PHP in there website -
* Facebook
* Yahoo
* Wikipedia
* Flicker
<?php
/*====================================*
Rules for PHP variables:
======================================*/
/*
=> A variable starts with the $ sign, followed by the name of the variable
=> A variable name must start with a letter or the underscore character
=> A variable name cannot start with a number
=> A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
=> Variable names are case-sensitive ($age and $AGE are two different variables)
*/
//PHP variable
$myfriend = 'my friend name is jahed hossain';
$br = '<br>';
echo $myfriend . $br;
?>
/*==================================
Operator
====================================*/
/*
1. Arithmetic Operator
2. Assignment Operator
3. Logical Operator
4. Comparison Operator
5. Array Operator
6. Increment/decrement Operator
7. String Operator
*/
<?php
/*
=======================
1. Arithmetic Operator
=======================
1.1 - Plus : +
1.2 - Mynus : -
1.3 - Into : *
1.4 - Devided : /
1.5 - Modulas : %
*/
$father = 60;
$son = 25;
$plus = $father + $son; //Plus
$mynus = $father - $son; //Mynus
$into = $father * $son; //Into
$devided = $father / $son; //Devided
$modulas = $father % $son; //Modulas
echo $plus . $br;
echo $mynus . $br;
echo $into . $br;
echo $devided . $br;
echo $modulas . $br;
?>
<?php
/*
=======================
2. Assignment Operator
=======================
2.1 - Plus-equal : +=
2.2 - Mynus-equal : -=
2.3 - Into-equal : *=
2.4 - Devided-equal : /=
2.5 - Modulas-equal : %=
*/
$age = 20;
$age = $age += 5; //Plus-equal
//$age = $age -= 5; //Mynus-equal
//$age = $age *= 5; //Into-equal
//$age = $age /= 5; //Devided-equal
//$age = $age %= 5; //Modulas-equal
echo $age . $br;
?>
<?php
/*
=======================
3. Logical Operator
=======================
3.1 - (or) - ||
3.2 - (and) - &&
3.3 - (not) - !
*/
$username = 'humayunahmed8';
$password = 'ha154248';
// (and)
if($username == 'humayunahmed8' && $password == 'ha154248'){
echo 'login success' . $br;
}else{
echo 'login failed' . $br;
}
//(or)
/*
if($username == 'humayunahmed8d' || $password == 'ha154248'){
echo 'login success';
}else{
echo 'login failed';
}
*/
?>
<?php
/*
=======================
4. Comparison Operator
=======================
4.1 - (equal) - ==
4.2 - (not equal) - !=
4.3 - (not equal) - <>
4.4 - (greater than) - >
4.5 - (greater than or equal to) - >=
4.6 - (less than) - <
4.7 - (less than or equal to) - <=
*/
$humayun = 20;
$jahed = 18;
if($humayun > $jahed){
echo 'true' . $br;
}else{
echo 'false' . $br;
}
$humayra = 17;
if($humayra >= 18){
echo 'Ready for marriage' . $br;
}else{
echo 'not ready for marriage' . $br;
}
?>
<?php
/*
=======================
5. Array Operator
=======================
5.1 - Indexed Array
5.2 - Associative Array
5.3 - Multidimensional Array
*/
// 5.1 - Indexed Array
$father = array(1=>'humayun','foysal','fariya');
//print_r($father);
echo $father[1] . $br;
// 5.2 - Associative Array
$mother = array('humayun'=>21,'foysal'=>18,'fariya'=>10);
//print_r($mother);
echo $mother['foysal'] . $br;
// 5.3 - Multidimensional Array
$humayun = array(
'humayra' => array(
'class' => 12,
'group' => 'Business Studies',
'hobby' => 'Reading',
),
'abrar' => array(
'class' => 10,
'group' => 'Science',
'hobby' => 'Sleeping',
) ,
'jahanara' => array(
'class' => 9,
'group' => 'Humanities',
'hobby' => 'Singing',
)
);
//print_r($humayun);
//echo $humayun['humayra']['hobby'];
//echo $humayun['abrar']['group'];
//echo $humayun['jahanara']['class'];
echo $humayun['humayra']['hobby'].$br.$humayun['abrar']['group'].$br.$humayun['jahanara']['class'] . $br;
?>
<?php
/*
==============
Loop
==============
1. for loop
2. while loop
3. foreach loop
*/
//1. for loop
//for(initialization,condition,increment/decrement);
for($i=100;$i>=1;$i--){
echo $i . $br;
}
//1++
for($b=1;$b<=100;$b++){
echo $b . $br;
}
//2+2=4+2=6+2=8
for($b=2;$b<=100;$b+=2){ // assign
echo $b . $br;
}
//1+2=3+2=5+2=7
for($b=1;$b<=100;$b+=2){ // assign
echo $b . $br;
}
//2. while loop
$n=1;
while($n<=100){
echo $n . $br;
$n++;
}
//3. foreach loop
$rahman = array('ramim'=>20,'nadim'=>25,'hridoy'=>30,'sakib'=>28);
foreach($rahman as $child=>$year){
//echo $child . $year . $br ;
echo $child . ' age is' . $year . $br;
}
?>
view raw php-loop.php hosted with ❤ by GitHub