PHP for WordPress
Official Documentation Coding Standards
From the Official Documentation : I choose two options :
PHP for WordPress -- Variables
PHP for WordPress - Variables
<?php
$varaiable1 = "Hello world";
echo $variable1;
Variables always start with $
PHP for WordPress -- Conditional
PHP for WordPress -- Conditional
$mynumber = 15;
if ($mymber > 10) {
echo 'number bigger than 10'
}
else
{
echo 'number smaller than 10';
}
PHP for WordPress -- Loops
PHP for WordPress -- Loops
Official documentation WP Loop (Please Read)
<?php
if ( have_posts() ) :
while ( have_posts() ) : the_post();
the_title( '<h2>', '</h2>' );
the_post_thumbnail();
the_excerpt();
endwhile;
else:
_e( 'Sorry, no posts matched your criteria.', 'textdomain' );
endif;
This was an example of the famous WP loop.
Below are noted for the PHP loops
---with the break, we go out from the loop
PHP for WordPress -- Functions
PHP for WordPress -- Functions
function add($var1, $var2) {
return $var1 + $var2;
}
$result1 = add(5, 3); //= 8
echo $result1;
Start with the word Function
Maybe accepts input (it can have defaults)
We invoke it from our site.