カテゴリー 全て - template - development - functions - styles

によって Ragnar Lodbrock 7年前.

2128

WordPress

WordPress theme development involves creating and customizing themes to alter the appearance and functionality of a website. A core component is "the loop," which checks for available content and displays it using a WHILE loop, often starting with a conditional statement.

WordPress

WordPress

php

PHP for Wordpress
Variables

arguments for The loop

$arg = array(...);

$user_full_name = "Rollo Lothbrock";

usefull only when you writing your custom code

Hooks

Filters

add_filter()

Let you modify existing content in WordPress

limit the number of post characters displayed

add custom footer to the bottom of a post

Actions

add_action( 'after_setup_theme', 'tweentyfevteen_theme' );

Your custom code that run when some specific action is takingl place

run some code when

whene menu is loaded

post is saved

Functions

inside every theme there are specific functions for the theme

Custom functions

The Loop

Custom Loops

WP_Query

$query = new WP_Query( $args );

$args = ( array { 'post_type' => 'post', 'order' => 'DES' })

"list of specification for the WP_Query"

dispaly a list of links to your posts on a custom page

Enables you to writes loop that do anything you want on a custom pages

all the code inside

Conditional Tags

+ simple loop

IF (There are post) WHILE (There are posts) ECHO post title ECHO post content ELSE ECHO "Sorry no post yet..."

Template tags

get_template_part( 'content', none )

displays "No post published yet" part of a template

get_header()

pre-made functions to use in WordPress themes

info

Coding standards

HTML makup with PHP

rather outside the blocks

one php block for a file

you don't need to close this block

server will do this for you

exclusivly writen php

types of PHP files in WP

plugin files

inside wp-content/plugins

PHP (HTML+CSS+JS)

theme files

dont make changes directly in theme folder

make an chlid-theme folder instead

inside wp-content/themes

HTML + PHP

core files

all WP files besides wp-content folder

only PHP

Theme Developement

The loop
using

normal method

short method

it can be closed at the end of the file

Checks what content is available

then with WHILE loop over it to display content on the website

It starts with conditional statement to
Files
index.php

to get header and footer

footer.php

dynamic copyright year

all the footer code

header.php

instead of all links to css, and scripts

<?php wp_title(); ?>

all from to

functions.php

including js files in the template

?>

add_action( 'wp_enqueue_scripts', 'name_theme_js' );

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) );

wp_enqueue_script( 'modernizr_js', get_template_directory_uri() . '/js/modernizr.js', '', '', false );


wp_enqueue_script( 'foundation_js', get_template_directory_uri() . '/js/foundation.js', 'array('jQuery')', '', true );

WordPress already has jQuery

to run jQuery code with $ sign

jQuery(document).ready(function($) { $code goeas here });

wrap it into noConflict wrapper

including css in the template

add_action( 'wp_enqueue_scripts' , 'name_theme_styles' );

function name_theme_styles() {

wp_enqueue_style( 'name_css', get_template_directory_uri() . 'path.css' );

}

ex.


wp_enqueue_style( 'foundation_css', get_template_directory_uri() . '/css/foundation.css' );

wp_enqueue_style( 'font_css', 'http://fonts.googleapis.com/css?family=Asap:400,700,400italic,700italic' );

style.css

include metainformations of a template