Tuesday, 08 December 2020 15:06

WordPress & PHP

Written by
Rate this item
(0 votes)

PHP for WordPress

 

Official Documentation  Coding Standards

 

From the Official Documentation :  I choose two options :

 

Zen Developer Zone

 

Sitepoint

 

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.

 

 

 

Read 240 times Last modified on Tuesday, 23 July 2024 08:17
Super User

      After Greek Army, I started with QBasic in QL, a computer brother of Spectrum, 2 Degrees, almost 2 Certificates, from GWBasic to Oracle Tech & IBM tech & Solaris Clusters, at almost 60s to CMS tech.

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.