+ All Categories
Home > Documents > Building excellent web experiences with Advanced Custom Fields ...

Building excellent web experiences with Advanced Custom Fields ...

Date post: 14-Feb-2017
Category:
Upload: lamdang
View: 238 times
Download: 4 times
Share this document with a friend
46
Building excellent web experiences with Advanced Custom Fields and Visual Composer Stanislav Khromov WordCamp Norrköping 2014
Transcript
Page 1: Building excellent web experiences with Advanced Custom Fields ...

Building excellent web experiences

with Advanced Custom Fields and Visual Composer

Stanislav KhromovWordCamp Norrköping 2014

Page 2: Building excellent web experiences with Advanced Custom Fields ...

About me

Stanislav KhromovWeb developer at IDG Sweden

Page 3: Building excellent web experiences with Advanced Custom Fields ...

This talk

● Setting up a good workflow for:Custom Post TypesCustom FieldsCustom Shortcodes

● Providing a good experience for content publishers

● Case study - event sites

Page 4: Building excellent web experiences with Advanced Custom Fields ...

Meet the cast

WordPress Core features● Post Types● Custom fields● Shortcodes

[gallery]

[gallery ids="729,732,731"]

Page 5: Building excellent web experiences with Advanced Custom Fields ...

Meet the cast

Plugins● Custom Post Type UI● Advanced Custom Fields● MinQueue● Visual Composer

Page 6: Building excellent web experiences with Advanced Custom Fields ...

Custom Post Types - Goals

What do we want?

● Visual interface for creating a CPT● No configuration in the database!● Separate CPT configuration into different

files● Autoloading

Page 7: Building excellent web experiences with Advanced Custom Fields ...

Custom Post Types - Example

Interface for creating a custom post type i Custom Post Types UI.

Don’t forget the Advanced Options!

Page 8: Building excellent web experiences with Advanced Custom Fields ...

Custom Post Types - Exporting

CPT UI lets us export to code!But where do we put this code and how do we organize it?

Page 9: Building excellent web experiences with Advanced Custom Fields ...

Custom Post Types - A plugin

Our CPT Plugin● Each CPT in a separate file● Plugin handles loading of the CPT:s

● Basic folder structure:

Page 10: Building excellent web experiences with Advanced Custom Fields ...

Custom Post Types - custom-cpt.php

Problem:Post types will be loaded twice. (Once from code, once from database.)

Page 11: Building excellent web experiences with Advanced Custom Fields ...

Custom Post Types - custom-cpt.phpSolution:Add a config variable to wp-config.php and load conditionally.

Page 12: Building excellent web experiences with Advanced Custom Fields ...

Custom Post Types - custom-cpt.phpImproved Custom CPT plugin:

Page 13: Building excellent web experiences with Advanced Custom Fields ...

Thought processCreate CPT (Visual)

Configure CPT (Visual) Export to PHP file

Commit to version control

Page 14: Building excellent web experiences with Advanced Custom Fields ...

What did we accomplish?

★ Visual interface for creating a CPT★ No configuration in the database!★ Separate CPT configuration into different files★ Autoloading

Result = A good workflow for working with Custom Post Types

Page 15: Building excellent web experiences with Advanced Custom Fields ...

Moving on toCustom Fields

Page 16: Building excellent web experiences with Advanced Custom Fields ...

Custom Fields

What do we want?

● Visual interface for creating fields● No configuration in the database!● Separate field configuration into logical

groups● Autoloading

Page 17: Building excellent web experiences with Advanced Custom Fields ...

Custom Fields - Example

Advanced Custom Fields provides an interface for creating custom fields that are grouped into Field Groups - collection of fields that can be attached onto a post type.

Page 18: Building excellent web experiences with Advanced Custom Fields ...

Custom Fields - Exporting

ACF lets us export field groups!

Page 19: Building excellent web experiences with Advanced Custom Fields ...

Custom Fields - PluginYou know the drill.

Same basic idea as the CPT plugin!

Page 20: Building excellent web experiences with Advanced Custom Fields ...

Thought processCreate field groups and fields (Visual)

Configure field groupsand fields (Visual)

Export to PHP file

Commit to version control

Page 21: Building excellent web experiences with Advanced Custom Fields ...

What did we accomplish?

★ Visual interface for creating fields★ No configuration in the database!★ Separate field configuration into logical groups★ Autoloading

Result = A good workflow for working with fields

Page 22: Building excellent web experiences with Advanced Custom Fields ...

Moving on to[shortcodes]

Page 23: Building excellent web experiences with Advanced Custom Fields ...

Shortcodes

What do we want?● Separate shortcodes into portable

packages.● Handle dependencies (CSS, Javascript,

Images, PHP libraries)● Internationalization● Autoloading

Page 24: Building excellent web experiences with Advanced Custom Fields ...

A typical shortcode

● Main shortcode logic● Templates● Resources

CSS (Regular + Responsive)JavaScriptImages

● Dependencies

Page 25: Building excellent web experiences with Advanced Custom Fields ...

Custom Shortcodes plugin

Page 26: Building excellent web experiences with Advanced Custom Fields ...

Custom Shortcodes plugin

Page 27: Building excellent web experiences with Advanced Custom Fields ...

A typical shortcode

Page 28: Building excellent web experiences with Advanced Custom Fields ...

A typical shortcode - CSS

+ media queries in separate file

Page 29: Building excellent web experiences with Advanced Custom Fields ...

Custom Shortcodes plugin

● More autoloaders!Load libraries on plugins_loadedLoad shortcodes on after_setup_themeLoad CSS/JS on wp_enqueue_scripts

Page 30: Building excellent web experiences with Advanced Custom Fields ...

Shortcodes

What did we accomplish?★ Separate shortcodes into portable

packages.★ Handle dependencies (CSS, Javascript,

Images, PHP libraries)★ Internationalization★ Autoloading

Page 31: Building excellent web experiences with Advanced Custom Fields ...
Page 32: Building excellent web experiences with Advanced Custom Fields ...

Performance

● OpCode cache solves issues with including files

● MinQueue integration lets us concatenate all CSS and JS into one file.

http://wordpress.org/plugins/minqueue/

Page 33: Building excellent web experiences with Advanced Custom Fields ...

Let’s talkuser experience

Page 34: Building excellent web experiences with Advanced Custom Fields ...

Visual Content Builders

● More user friendly than shortcodes● Enhance content publisher flexibility● Each shortcode becomes a “block” in the

visual editor

Page 35: Building excellent web experiences with Advanced Custom Fields ...

Before and after

Page 37: Building excellent web experiences with Advanced Custom Fields ...

Integrating a shortcode is easy!

Documentation of parameters available at:http://kb.wpbakery.com/index.php?title=Vc_map

From regular shortcode to Visual Composer block in a few rows of code!

Page 38: Building excellent web experiences with Advanced Custom Fields ...

Integrating a shortcode is easy!

But where do we put this code?

Page 39: Building excellent web experiences with Advanced Custom Fields ...

Our shortcode plugin!

● Since Visual Composer is based around shortcodes, let’s use our Shortcodes plugin for this.

Page 40: Building excellent web experiences with Advanced Custom Fields ...

Thought process

● Data that belongs to our custom post type is stored in custom fields on the custom post type.

● Data that controls how blocks are displayed on the frontend is put into the block configuration.

Page 41: Building excellent web experiences with Advanced Custom Fields ...

Case Study

Page 42: Building excellent web experiences with Advanced Custom Fields ...

IDG Event Sites

● Unify event site creation into a single platform

● Enable full flexibility for content publishers● Enable easy maintenance

Page 43: Building excellent web experiences with Advanced Custom Fields ...

End results

● 3 custom post types● 12 custom field groups● 21 shortcodes● Completely block-based

Page 44: Building excellent web experiences with Advanced Custom Fields ...

http://computersweden.event.idg.se

Demo!

Page 45: Building excellent web experiences with Advanced Custom Fields ...

Open source!

● Source code for CPT, Custom Fields and Shortcodes loader plugins available on GitHub with examples from this talk!

https://github.com/khromov/wp-custom-cpthttps://github.com/khromov/wp-custom-fieldshttps://github.com/khromov/wp-custom-shortcodes

Page 46: Building excellent web experiences with Advanced Custom Fields ...

Thank you!

Questions?


Recommended