od zera do motywów kodera
TRANSCRIPT
![Page 1: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/1.jpg)
Od zera do motywów kodera
1
![Page 2: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/2.jpg)
Dawid Szwed
@szweddawid
2
![Page 3: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/3.jpg)
Podstawowe pliki
wp-content/themes/wordup-silesiastyle.css
index.php
3
![Page 4: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/4.jpg)
Podstawowe pliki - style.css
/*
Theme Name: WordUp SilesiaTheme URI: http://wp360.pro/themes/wordup-silesiaAuthor: Dawid SzwedAuthor URI: http://wp360.pro/Description: Theme descriptionText Domain: wp360
*/
4
![Page 5: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/5.jpg)
Podstawowe pliki - index.php
<html><head>
<?php wp_head(); ?></head>
<body <?php body_class();?>><h1>WordUp Silesia Theme</h1><?php wp_footer(); ?>
</body></html>
5
wp_head()wp_footer()body_class()
![Page 6: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/6.jpg)
Pętla
… <body <?php body_class(); ?>>
<?php if( have_posts() ): ?><?php while(have_posts()): the_post(); ?>
<h2><?php the_title(); ?></h2><?php the_excerpt(); ?><a href=”<?php the_permalink(); ?>”>Read more</a>
<?php endwhile; ?><?php else: ?>
No posts<?php endif; ?><?php wp_footer(); ?>
</body>… 6
global $wp_queryhave_posts()
the_post()the_title()
![Page 7: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/7.jpg)
Pojedynczy wpis
single.phpwłasny typ wpisu (CPT)
7
![Page 8: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/8.jpg)
Pojedynczy wpis - kod… <body <?php body_class(); ?>>
<?php if( have_posts() ): ?><?php while(have_posts()): the_post(); ?>
<article <?php post_class();?>><h1><?php the_title(); ?></h1><?php the_content(); ?>
</article><?php endwhile; ?>
<?php else: ?>No content
<?php endif; ?><?php wp_footer(); ?>
</body>… 8
![Page 9: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/9.jpg)
Powtarzalne elementy
get_template_part()
get_template_part(‘loop’) => loop.php
get_template_part(‘loop’, ‘single’) => loop-single.php
get_template_part(‘templates/loop’, ‘single’) => templates/loop-single.php
9
![Page 10: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/10.jpg)
Powtarzalne elementy
get_header(), get_footer(), get_sidebar()get_header() => get_template_part(‘header’) =>
header.phpget_header(‘blog’) => header-blog.php
10
![Page 11: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/11.jpg)
Pojedyncza strona - page.php… <body <?php body_class(); ?>>
<?php if( have_posts() ): ?><?php while(have_posts()): the_post(); ?>
<article <?php post_class();?>><h1><?php the_title(); ?></h1><?php the_content(); ?>
</article><?php endwhile; ?>
<?php else: ?>No content
<?php endif; ?><?php wp_footer(); ?>
</body>… 11
![Page 12: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/12.jpg)
Pojedynczy wpis i strona
/* single.php */<?php get_header(); get_template_part(‘loop’, ‘single’);get_footer();?>
12
/* page.php */<?phpget_header(); get_template_part(‘loop’, ‘single’);get_footer();?>
![Page 13: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/13.jpg)
Pojedynczy wpis i strona
/* loop-single.php */<?php if( have_posts() ): ?>
<?php while(have_posts()): the_post(); ?><article <?php post_class();?>>
<h1><?php the_title(); ?></h1><?php the_content(); ?>
</article><?php endwhile; ?>
<?php else: ?>No content
<?php endif; ?> 13
![Page 14: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/14.jpg)
Pojedynczy wpis i strona
/* header.php */<html>
<head><?php
wp_head(); ?></head>
<body <?php body_class();?>>
14
/* footer.php */<?php wp_footer(); ?></body></html>
![Page 15: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/15.jpg)
Inne szablony
singular.php (WP 4.3)
search.php
404.php
taxonomy.php
single-{cpt-slug}.php
archive-{cpt-slug}.php
15
![Page 16: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/16.jpg)
Inne szablony
front-page.phphome.php
16
![Page 17: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/17.jpg)
Szablony stron
my-page.phptemplates/my-page.php
/* Template Name: My Page */
17
![Page 18: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/18.jpg)
Hierarchia szablonów
18
![Page 19: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/19.jpg)
19https://developer.wordpress.org/files/2014/10/template-hierarchy.png
![Page 20: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/20.jpg)
Menu, sidebar, style, JS…
functions.php
20
![Page 21: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/21.jpg)
Dołączanie stylów
function wordup_enqueue_style() {wp_enqueue_style( 'core', 'style.css', false );
}
function wordup_enqueue_script() {wp_enqueue_script( 'my-js', 'main.js', false );
}
add_action( 'wp_enqueue_scripts', 'wordup_enqueue_style' );add_action( 'wp_enqueue_scripts', 'wordup_enqueue_script' );
21
![Page 22: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/22.jpg)
Rejestracja menu
add_action( 'after_setup_theme', 'wordup_menu' );function wordup_menu() {
register_nav_menu( 'primary', __('Primary Menu', ‘wordup’) );}
22
![Page 23: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/23.jpg)
Wyświetlanie menu - header.php
<html><head>
<?php wp_head(); ?></head>
<body <?php body_class();?>><?php wp_nav_menu( array(
'theme_location' => 'primary') ); ?> 23
![Page 24: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/24.jpg)
Rejestracja sidebarów
add_action( 'widgets_init', 'wordup_widgets_init' );function wordup_widgets_init() { register_sidebar( array(
'name' => ‘Main sidebar’,'id' => 'main-sidebar','description' => ‘Main sidebar displayed
on every page') );
}24
![Page 25: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/25.jpg)
Wyświetlanie sidebarów
<ul id="sidebar"><?php dynamic_sidebar( 'main-
sidebar' ); ?></ul>
25
![Page 26: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/26.jpg)
Motyw potomny (Child theme)
wordup-silesia-childstyle.css
functions.phpnadpisywanie plików
26
![Page 27: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/27.jpg)
Motyw potomny (Child theme)
/*Theme Name: WordUp Silesia ChildTheme URI: http://wp360.pro/themes/wordup-silesiaAuthor: wp360Author URI: http://wp360.pro/Description: Theme descriptionTemplate: wordup-silesia
*/27
![Page 28: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/28.jpg)
Motyw potomny (Child theme)
if(!function_exists(‘wordup_my_function’)){
function wordup_my_function() {}
}28
![Page 29: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/29.jpg)
Czego w motywie nie umieszczać?
rejestracji typów wpisów (CPT)
rejestracji taksonomii
logiki biznesowej
29
![Page 30: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/30.jpg)
Przydatne wtyczki
Reveal Templatehttps://pl.wordpress.org/plugins/reveal-template/
Theme Checkhttps://pl.wordpress.org/plugins/theme-check/
30
![Page 31: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/31.jpg)
Źródła
http://codex.wordpress.org/Theme_Development#Anatomy_of_a_Theme
https://codex.wordpress.org/Template_Tagshttps://codex.wordpress.org/Class_Reference/WP_Queryhttps://developer.wordpress.org/themes/basics/template-hierarchy/https://codex.wordpress.org/Child_Themeshttps://codex.wordpress.org/Function_Reference/
31
![Page 32: Od zera do motywów kodera](https://reader034.vdocuments.net/reader034/viewer/2022052602/588090591a28ab35718b777b/html5/thumbnails/32.jpg)
Dziękuję
32