Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Como criar um tema para WordPress

Como criar um tema para WordPress

Aprenda na prática como criar um tema para o WordPress do zero, usando HTML e CSS puro, ou usando ferramentas disponíveis na Internet, com um passo a passo.

Palestra apresentada na Campus Party Brasil 2014.

Avatar for Claudio Sanches

Claudio Sanches

January 31, 2014
Tweet

More Decks by Claudio Sanches

Other Decks in Programming

Transcript

  1. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal @ClaudioSMweb

    Programador PHP, Python e Ruby; Desenvolve com WordPress há 6 anos; Possui mais de 30 plugins no repositório oficial do WordPress; Líder do projeto Odin Framework; Trabalha atualmente na Infranology.
  2. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal @RafaelFunchal

    Publicitário, Designer e músico nas horas vagas; Desenvolve com WordPress há 5 anos; Administrador do grupo WordPress Brasil no Facebook; Também participa do projeto Odin Framework.
  3. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal Como

    funciona um tema? De forma básica, funciona com arquivos de templates que carregaram funções com loops/laços para a exibição do conteúdo. Todo o conteúdo virá do banco de dados e desta forma você poderá usar o tema em outros sites/blogs sem nenhum problema.
  4. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal Arquivos

    obrigatórios Os arquivos mínimos para o funcionamento do tema são: style.css header.php index.php footer.php
  5. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal Este

    é o arquivo mais importante! É ele que registra o tema no WP! /* Theme Name: Nome do seu tema Theme URI: Site ou documentação do tema. Description: Descrição do tema Author: Nome do autor Author URI: Site do autor Version: 1.0.0 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html */ style.css
  6. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal Precisará

    pelo menos ter o seguinte formato: <!DOCTYPE html> <html <?php language_attributes(); ?>> <head> <meta charset="<?php bloginfo( 'charset' ); ?>" /> <title><?php wp_title(); ?></title> <link rel="stylesheet" href=" <?php echo get_stylesheet_uri(); ? >" type="text/css" media="screen" /> <?php wp_head(); ?> </head> <body <?php body_class(); ?>> header.php
  7. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal index.php

    Exemplo bem simples de um template com loop/laço: <?php get_header(); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <article id="post- <?php the_ID(); ?>" <?php post_class(); ?>> <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ? ></a></h3> <div class="entry-content"> <?php the_content(); ?></div> </article> <?php endwhile; endif; ?> <?php get_footer(); ?> http://codex.wordpress.org/The_Loop
  8. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal Outras

    funções dentro do loop/laço Veja mais alguns exemplos de funções que exibem conteúdo dentro do loop: the_excerpt() // Resumo do post the_category() // Exibe uma lista de categorias do post the_tags() // Exibe uma lista de tags do post the_author() // Nome do autor the_time( 'd/m/Y' ) // Data da publicação
  9. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal Exemplo

    para o rodapé: <?php wp_footer(); ?> </body> </html> footer.php
  10. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal Custom

    Post Type archive-{post_type}.php archive.php index.php Author author-{nicename}.php author-{id}.php author.php archive.php index.php Anexos MIME_type.php Hierarquia dos arquivos Home home.php index.php Front Page front-page.php index.php Single single-{post_type}.php single.php index.php Page page-{slug}.php page-{id}.php page.php index.php Categoria category-{slug}.php category-{id}.php category.php archive.php index.php Tag tag-{slug}.php tag-{id}.php tag.php archive.php index.php Taxonomies taxonomy-{taxonomy}.php taxonomy.php archive.php index.php Date date.php archive.php index.php Resultado da Pesquisa search.php index.php 404 404.php index.php http://codex.wordpress.org/Template_Hierarchy
  11. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal É

    possível criar funções que poderão ser acessadas de qualquer parte do tema através do arquivo functions.php. E até mesmo é possível alterar o comportamento do Front-end e Back-end trabalhando com filtros (add_filter()) e ganchos (add_action()) . Funções personalizadas
  12. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal Exemplo

    de como carregar scripts no WordPress: function odin_enqueue_scripts() { wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'theme-scripts', get_template_directory_uri() . '/js/scripts.js', array( 'jquery' ), '1.0', true ); } add_action( 'wp_enqueue_scripts', 'odin_enqueue_scripts', 1 ); Exemplo de gancho/action http://codex.wordpress.org/Plugin_API/Action_Reference
  13. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal Exemplo

    de como alterar uma função no WordPress: function odin_excerpt_more( $output ) { $read_more = '<br /><a href="' . get_permalink() . '">' . __( 'Continue lendo...' ) . '</a>'; return $output . $read_more; } add_filter( 'get_the_excerpt', 'odin_excerpt_more' ); Exemplo de filtro/filter http://codex.wordpress.org/Plugin_API/Filter_Reference
  14. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal Veja

    alguns exemplos: is_home() // Homepage is_front_page() // Front page is_page() // Páginas is_single() // Posts is_category() // Arquivos de categoria is_admin() // Página de administração do WordPress wp_is_mobile() // Verifica o acesso por um dispositivo mobile Tags/funções condicionais http://codex.wordpress.org/Conditional_Tags
  15. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal Registrando

    novas features Você pode registrar diversas novas features para usar no seu tema: register_nav_menu() // Menus dinâmicos register_sidebar() // Sidebars/barra lateral register_post_type() // Novo tipo de conteúdo register_taxonomy() // Nova taxonomia
  16. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal APIs

    disponíveis Existem várias APIs dentro do WP e as mais interessantes para temas são: Settings API => Permite criar opções no administrador Theme Customization API => Cria um menu para customizar o tema Widgets API => Permite criar novos widgets Shortcode API => Cria pequenos trechos de código para inserir conteúdo extra ou dinâmico dentro dos posts/páginas. http://codex.wordpress.org/WordPress_APIs
  17. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal É

    possível aproveitar um tema que já existe para ser usado como base. Neste caso a base será o tema PAI e o seu novo tema o FILHO. Tema PAI e FILHO devem estar em pastas separadas dentro de wp- content/themes e indicar quem é o PAI pelo style.css: /* Theme Name: Nome do seu filho ... Template: nome-da-pasta-do-tema-pai ... Temas filhos http://codex.wordpress.org/Child_Themes
  18. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal Starter

    Themes _s (Underscores) Roots Gantry Bones Quark Whiteboard Hybrid Core BootstrapWP Thesis
  19. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal http://codex.wordpress.org/Theme_Development

    http://codex.wordpress.org/Template_Hierarchy http://codex.wordpress.org/Function_Reference/get_header http://codex.wordpress.org/Function_Reference/get_footer http://codex.wordpress.org/Function_Reference/wp_head http://codex.wordpress.org/Function_Reference/wp_footer http://codex.wordpress.org/Function_Reference/language_attributes http://codex.wordpress.org/Function_Reference/bloginfo http://codex.wordpress.org/Function_Reference/wp_title http://codex.wordpress.org/Function_Reference/get_stylesheet_uri http://codex.wordpress.org/Function_Reference/body_class http://codex.wordpress.org/The_Loop http://codex.wordpress.org/Function_Reference/have_posts http://codex.wordpress.org/Function_Reference/the_post Links e referências
  20. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal http://codex.wordpress.org/Function_Reference/the_ID

    http://codex.wordpress.org/Function_Reference/post_class http://codex.wordpress.org/Function_Reference/the_permalink http://codex.wordpress.org/Function_Reference/the_title http://codex.wordpress.org/Function_Reference/the_content http://codex.wordpress.org/Function_Reference/the_excerpt http://codex.wordpress.org/Function_Reference/the_category http://codex.wordpress.org/Function_Reference/the_tags http://codex.wordpress.org/Function_Reference/the_author http://codex.wordpress.org/Function_Reference/the_time http://codex.wordpress.org/Function_Reference/the_date http://codex.wordpress.org/Plugin_API/Action_Reference http://codex.wordpress.org/Plugin_API/Filter_Reference http://codex.wordpress.org/Function_Reference/add_filter Links e referências
  21. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal http://codex.wordpress.org/Function_Reference/add_action

    http://codex.wordpress.org/Function_Reference/wp_enqueue_script http://codex.wordpress.org/Function_Reference/get_template_directory_uri http://codex.wordpress.org/Function_Reference/get_permalink http://codex.wordpress.org/Conditional_Tags http://codex.wordpress.org/Function_Reference/is_home http://codex.wordpress.org/Function_Reference/is_front_page http://codex.wordpress.org/Function_Reference/is_page http://codex.wordpress.org/Function_Reference/the_date http://codex.wordpress.org/Plugin_API/Action_Reference http://codex.wordpress.org/Plugin_API/Filter_Reference http://codex.wordpress.org/Function_Reference/add_filter http://codex.wordpress.org/Function_Reference/add_action http://codex.wordpress.org/Function_Reference/wp_enqueue_script Links e referências
  22. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal http://codex.wordpress.org/Function_Reference/get_template_directory_uri

    http://codex.wordpress.org/Function_Reference/get_permalink http://codex.wordpress.org/Conditional_Tags http://codex.wordpress.org/Function_Reference/is_home http://codex.wordpress.org/Function_Reference/is_front_page http://codex.wordpress.org/Function_Reference/is_page http://codex.wordpress.org/Function_Reference/is_single http://codex.wordpress.org/Function_Reference/is_category http://codex.wordpress.org/Function_Reference/is_admin http://codex.wordpress.org/Function_Reference/wp_is_mobile http://codex.wordpress.org/Function_Reference/register_nav_menu http://codex.wordpress.org/Function_Reference/register_sidebar http://codex.wordpress.org/Function_Reference/register_post_type http://codex.wordpress.org/Function_Reference/register_taxonomy Links e referências
  23. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal http://codex.wordpress.org/Settings_API

    http://codex.wordpress.org/Theme_Customization_API http://codex.wordpress.org/Widgets_API http://codex.wordpress.org/Shortcode_API http://codex.wordpress.org/Child_Themes Links e referências
  24. Como criar um tema para WordPress @ClaudioSMweb | @RafaelFunchal Este

    documento esta licenciado sobre GPLv2. É possível encontrar uma cópia da licença no seguinte link: http://www.gnu.org/licenses/gpl-2.0.txt Licença