Wordpress

Hooks, loops, functions

Att kunna

  • Child Theme - Måste ha en förälder, utökar tema
  • Page Template - Mallar för Pages
  • functions.php - Filen för all custom php
  • style.css - Filen för all custom css
  • frontpage.php - Mallen för statisk hemsida
  • home.php - Mallen för blogginlägg

WordPress Codex - Bibeln

https://codex.wordpress.org/

Custom Queries

if ( have_posts() ) :
  while ( have_posts() ) : the_post();
    get_template_part( 'template-parts/content', get_post_format() );
  endwhile;

https://codex.wordpress.org/The_Loop

Ungefärligt översatt till PHP

foreach($posts as $post){
  require 'post-content.php';
}

Funktioner som returnerar innehållet

  • the_title - titeln
  • the_content - själva inlägget
  • the_thumbnail - "Featured Image"
  • the_category - kategorin/er
  • the_post_meta - metadata, författare etc.

WP_Query

https://codex.wordpress.org/Class_Reference/WP_Query

$the_query = new WP_Query( $arguments );

if ( $the_query->have_posts() ) :
  while ( $the_query->have_posts() ) :
    $the_query->the_post();
  endwhile;

Vi måste skriva variabelnamnet före allt

$query = new WP_Query( array( 'author' => 5 ) );
$query = new WP_Query( array( 'category_name' => 'cats' ) );
$query = new WP_Query( array( 'tag' => 'sports' ) );
$query = new WP_Query( 
  array( 
    'tag'             => 'sports',
    'posts_per_page'  => '10'
  )
);

Bra lista på hjälpsamma funktioner

https://github.com/taniarascia/wp-functions

Hooks

https://codex.wordpress.org/Plugin_API/Action_Reference

Vi har två sätt att modifiera innehåll via hooks

  • actions - kör handlingar vid vissa tillfällen
  • filters - filtrerar innehåll vid vissa tillfällen

add_action('init', 'my_custom_function');
add_filter('the_title', 'my_title_function');
function profanity_filter($text) {
  $words = array("illuminati", "big brother", "deep state");
  /* str_replace checks for words in the array and removes them from
   * the content in the post, returning a bleeped version */
  return str_replace($words, "BLEEP", $text);
}

add_filter('the_content', 'profanity_filter');

Att tänka på: bilder

Använd Wordpress inbyggda bildhanteringssystem

Kör bilderna genom ImageOptim / FileOptimizer

Tänk på att ändra thumbnail size

Bestäm idag vilken typ av sida ni ska göra

Börja skissa upp upplägget: wireframes kan vara en bra idé

Informera mig om vad ni ska göra innan dagen är slut