WordPress
Theme Developement
Files
style.css
include metainformations of a template
functions.php
including css in the template
<?php
function name_theme_styles() {
wp_enqueue_style( 'name_css', get_template_directory_uri() . 'path.css' );
ex.
}
add_action( 'wp_enqueue_scripts' , 'name_theme_styles' );
including js files in the template
WordPress already has jQuery
to run jQuery code with $ sign
wrap it into noConflict wrapper
jQuery(document).ready(function($) { $code goeas here });
function name_theme_js() {
wp_enqueue_script( 'name_js', get_template_directory_uri() . 'path.js', 'dependency(array(''))', 'version', do we wanna this in the footer(true/false) );
ex.
}
add_action( 'wp_enqueue_scripts', 'name_theme_js' );
?>
index.php
to get header and footer
<?php get_header(); ?>
header.php
all from <!doctype html> to <header/>
<title><?php wp_title(); ?></title>
<?php wp_head(); ?>
instead of all links to css, and scripts
<h1><a href="<?php wp_bloginfo('url'); ?>"><?php wp_bloginfo('name'); ?></a></h1>
<?php get_footer(); ?>
footer.php
all the footer code
dynamic copyright year
<?php echo_date('Y'); ?>
<?php wp_footer(); ?>
The loop
It starts with conditional statement to
Checks what content is available
then with WHILE loop over it to display content on the website
using
short method
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
it can be closed at the end of the file
<?php endif; ?>
normal method
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
//
// Post Content here
//
} // end while
} // end if
?>
php
PHP for Wordpress
info
types of PHP files in WP
core files
only PHP
all WP files besides wp-content folder
theme files
HTML + PHP
inside wp-content/themes
dont make changes directly in theme folder
make an chlid-theme folder instead
plugin files
PHP (HTML+CSS+JS)
inside wp-content/plugins
one php block for a file
exclusivly writen php
you don't need to close this block
server will do this for you
HTML makup with PHP
rather outside the blocks
Coding standards
Template tags
pre-made functions to use in WordPress themes
ex.
get_header()
get_template_part( 'content', none )
displays "No post published yet" part of a template
Conditional Tags
+ simple loop
IF (There are post) WHILE (There are posts) ECHO post title ECHO post content ELSE ECHO "Sorry no post yet..."
The Loop
First part of conditonal statemenet
all the code inside
End part of the conditional statement
Custom Loops
WP_Query
Enables you to writes loop that do anything you want on a custom pages
ex.
dispaly a list of links to your posts on a custom page
$args = ( array { 'post_type' => 'post', 'order' => 'DES' })
"list of specification for the WP_Query"
$query = new WP_Query( $args );
Functions
Custom functions
functions.php
inside every theme there are specific functions for the theme
Hooks
Actions
Your custom code that run when some specific action is takingl place
ex.
run some code when
post is saved
whene menu is loaded
add_action( 'after_setup_theme', 'tweentyfevteen_theme' );
Filters
Let you modify existing content in WordPress
add custom footer to the bottom of a post
limit the number of post characters displayed
add_filter()
Variables
usefull only when you writing your custom code
ex.
$user_full_name = "Rollo Lothbrock";
arguments for The loop
$arg = array(...);