SlideShare une entreprise Scribd logo
1  sur  21
Dynamic Sidebars and Widgets
Jason Yingling
Red8 Interactive
What is a sidebar?
• Sidebar can mean two things:
• An area to the side (but not always) of a post generally
containing information tangentially related to the main
content.
• Generally a themes sidebar.php
What is a sidebar?
• An area where widgets can be used within a theme.
Also known as a widgetized area.
• Created by using the register_sidebar() function
• Not strictly relegated to being used in sidebar.php.
Also commonly used in footers.
What is a widget?
• Bits of code that can be used in a widgetized
area to add functionality to WordPress sites.
Registering (Creating) a Widgetized Area
• Widgetized areas should be registered in the
theme as they are presentational. Generally in
functions.php.
• Widgetized area can be displayed in any template
file. Not tied to sidebar.php.
• register_sidebar($args) creates the widgetized
area
• add_action( ‘widgets_init’, $function) hooks into
WordPress to create a widgetized area when
WordPress initializes the widgets.
register_sidebar()
• Takes a single argument of an associative array of
parameters that set the options for the widget area.
• Wrap $args array and register_sidebar() in separate
function that can be called on ‘widgets_init’ hook
add_action(‘widgets_init’, ‘function_name’);
• Action hook in WordPress for connecting to the
widget initialization function
• Call previously defined function for registering a
sidebar as second parameter
• Allows WordPress to create the widget area in the
backend.
Displaying a Widgetized Area
• is_active_sidebar(‘widget_id’) – Checks to see if the
sidebar has any widgets activated. (optional)
• dynamic_sidebar(‘widget_id’) – Displays the
widgetized area and any widgets set inside it.
• Can be used within any template files.
Creating a Widget
• Custom widgets are created by a class that
extends the WP_Widget class.
• Widget is initiated by hooking
register_widget() into the ‘widgets_init’ action
hook
Extending the WP_Widget class
• By extending the WP_Widget class we can add
methods for our widget to use, as well as use
methods and properties present in the
WP_Widget class.
Constructing our Widget
• To construct our widget we use the parent
__construct function from the WP_Widget class
which takes 3 parameters
– ‘widget-id’ : The id / slug of the widget
– ‘Widget Name’ : The nice name to show on the
admin screen
– array() : An array of additional options
Constructing our widget
Displaying Widget Content
• To display the content of our widget we use
the widget() method
• widget() ‘echo’s a string wherever the widget
is placed on your site
• Takes two arguments:
– $args – Widget arguments
– $instance – Previously saved data in the database
Displaying Widget Content
Creating a Form for Editing Widget Content
• The form() method allows us to create HTML
form elements for storing data within the
widget
• Uses the $instance argument to store data for
the instance of the widget
Creating a Form for Editing Widget Content
Saving Widget Data
• To save the widget $instance we’ll use the
update() method
• Takes two arguments: $new_instance and
$old_instance
• $new_instance will contain the new values
entered in the widget’s form
• $old_instance will contain the previous values,
which are replaced with the $new_instance
on aving the form
Saving Widget Data
Registering the Widget
• Create a function to hold our
register_widget(‘Widget_Class’) function
• Hook in our newly created function into the
‘widgets_init’ action hook

Contenu connexe

Tendances

Tendances (20)

Presentation on Instant page speed optimization
Presentation on Instant page speed optimizationPresentation on Instant page speed optimization
Presentation on Instant page speed optimization
 
AEM (CQ) Dispatcher Security and CDN+Browser Caching
AEM (CQ) Dispatcher Security and CDN+Browser CachingAEM (CQ) Dispatcher Security and CDN+Browser Caching
AEM (CQ) Dispatcher Security and CDN+Browser Caching
 
AEM (CQ) Dispatcher Caching Webinar 2013
AEM (CQ) Dispatcher Caching Webinar 2013AEM (CQ) Dispatcher Caching Webinar 2013
AEM (CQ) Dispatcher Caching Webinar 2013
 
Fluxible
FluxibleFluxible
Fluxible
 
CS-Cart Advanced Backup Management
CS-Cart Advanced Backup ManagementCS-Cart Advanced Backup Management
CS-Cart Advanced Backup Management
 
Introducing WordPress Multitenancy (Wordcamp Vegas/Orlando 2015/WPCampus)
Introducing WordPress Multitenancy (Wordcamp Vegas/Orlando 2015/WPCampus)Introducing WordPress Multitenancy (Wordcamp Vegas/Orlando 2015/WPCampus)
Introducing WordPress Multitenancy (Wordcamp Vegas/Orlando 2015/WPCampus)
 
Introducing Wordpress Multitenancy
Introducing Wordpress MultitenancyIntroducing Wordpress Multitenancy
Introducing Wordpress Multitenancy
 
Drupal Multi-Site Setup
Drupal Multi-Site SetupDrupal Multi-Site Setup
Drupal Multi-Site Setup
 
Aem offline content
Aem offline contentAem offline content
Aem offline content
 
EVOLVE'13 | Enhance | Permission Sensitive Caching | Paul McMahon & Jason Rap...
EVOLVE'13 | Enhance | Permission Sensitive Caching | Paul McMahon & Jason Rap...EVOLVE'13 | Enhance | Permission Sensitive Caching | Paul McMahon & Jason Rap...
EVOLVE'13 | Enhance | Permission Sensitive Caching | Paul McMahon & Jason Rap...
 
Using multi-tenant WordPress to simplify development
Using multi-tenant WordPress to simplify developmentUsing multi-tenant WordPress to simplify development
Using multi-tenant WordPress to simplify development
 
Joomla! Day Deutschland 2012 - Advanced Akeeba Backup
Joomla! Day Deutschland 2012 - Advanced Akeeba BackupJoomla! Day Deutschland 2012 - Advanced Akeeba Backup
Joomla! Day Deutschland 2012 - Advanced Akeeba Backup
 
Introdcution to Adobe CQ
Introdcution to Adobe CQIntrodcution to Adobe CQ
Introdcution to Adobe CQ
 
Get Started in Professional WordPress Design & Development
Get Started in Professional WordPress Design & DevelopmentGet Started in Professional WordPress Design & Development
Get Started in Professional WordPress Design & Development
 
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 NepalWordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
 
CIRCUIT 2015 - Monitoring AEM
CIRCUIT 2015 - Monitoring AEMCIRCUIT 2015 - Monitoring AEM
CIRCUIT 2015 - Monitoring AEM
 
Introduction to CQ5
Introduction to CQ5Introduction to CQ5
Introduction to CQ5
 
Ch. 11 deploying
Ch. 11 deployingCh. 11 deploying
Ch. 11 deploying
 
WordPress Theme Development: Part 2
WordPress Theme Development: Part 2WordPress Theme Development: Part 2
WordPress Theme Development: Part 2
 
AEM - A Collection of developer friendly tools
AEM - A Collection of developer friendly toolsAEM - A Collection of developer friendly tools
AEM - A Collection of developer friendly tools
 

En vedette

WordCamp St. Louis 2014 WordPress for beginners by christoph trappe
WordCamp St. Louis 2014 WordPress for beginners by christoph trappeWordCamp St. Louis 2014 WordPress for beginners by christoph trappe
WordCamp St. Louis 2014 WordPress for beginners by christoph trappe
Christoph Trappe
 

En vedette (20)

Speeding Up WordPress sites
Speeding Up WordPress sitesSpeeding Up WordPress sites
Speeding Up WordPress sites
 
(( Lucas lima )) Managing WordPress Projects - STL Meetup August 2015
(( Lucas lima )) Managing WordPress Projects - STL Meetup August 2015(( Lucas lima )) Managing WordPress Projects - STL Meetup August 2015
(( Lucas lima )) Managing WordPress Projects - STL Meetup August 2015
 
Ithemes presentation
Ithemes presentationIthemes presentation
Ithemes presentation
 
WordPress Custom Post Types
WordPress Custom Post TypesWordPress Custom Post Types
WordPress Custom Post Types
 
Doing Things the WordPress Way
Doing Things the WordPress WayDoing Things the WordPress Way
Doing Things the WordPress Way
 
Managing_WordPress_Projects_wcstl 2015_Lucas_Lima
Managing_WordPress_Projects_wcstl 2015_Lucas_LimaManaging_WordPress_Projects_wcstl 2015_Lucas_Lima
Managing_WordPress_Projects_wcstl 2015_Lucas_Lima
 
Wordpress as a Backend
Wordpress as a BackendWordpress as a Backend
Wordpress as a Backend
 
Getting to Know Underscores
Getting to Know Underscores Getting to Know Underscores
Getting to Know Underscores
 
Teresa Lane - Content Modeling - WordCamp St. Louis 2016
Teresa Lane - Content Modeling - WordCamp St. Louis 2016Teresa Lane - Content Modeling - WordCamp St. Louis 2016
Teresa Lane - Content Modeling - WordCamp St. Louis 2016
 
Building a Simple Project Plan for WordPress Projects
Building a Simple Project Plan for WordPress ProjectsBuilding a Simple Project Plan for WordPress Projects
Building a Simple Project Plan for WordPress Projects
 
SEO – Technik, Struktur und Inhalt im Einklang
SEO – Technik, Struktur und Inhalt im EinklangSEO – Technik, Struktur und Inhalt im Einklang
SEO – Technik, Struktur und Inhalt im Einklang
 
Lady Blogger 2015 Conference
Lady Blogger 2015 ConferenceLady Blogger 2015 Conference
Lady Blogger 2015 Conference
 
Performics ces recap_deck
Performics ces recap_deckPerformics ces recap_deck
Performics ces recap_deck
 
Ensayo sobre word
Ensayo sobre wordEnsayo sobre word
Ensayo sobre word
 
Performics CES Recap Deck
Performics CES Recap DeckPerformics CES Recap Deck
Performics CES Recap Deck
 
Talk WordCamp Porto 2013
Talk WordCamp Porto 2013 Talk WordCamp Porto 2013
Talk WordCamp Porto 2013
 
Landing Page Best Practices
Landing Page Best PracticesLanding Page Best Practices
Landing Page Best Practices
 
WordCamp St. Louis 2014 WordPress for beginners by christoph trappe
WordCamp St. Louis 2014 WordPress for beginners by christoph trappeWordCamp St. Louis 2014 WordPress for beginners by christoph trappe
WordCamp St. Louis 2014 WordPress for beginners by christoph trappe
 
Protect Your WordPress Website - Setting Up IThemes Security
Protect Your WordPress Website - Setting Up IThemes SecurityProtect Your WordPress Website - Setting Up IThemes Security
Protect Your WordPress Website - Setting Up IThemes Security
 
Passwords, Attakcks, and Security, oh my!
Passwords, Attakcks, and Security, oh my!Passwords, Attakcks, and Security, oh my!
Passwords, Attakcks, and Security, oh my!
 

Similaire à Creating Dynamic Sidebars & Widgets in WordPress

Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
SPTechCon
 
SoftShake 2013 - Vaadin componentization
SoftShake 2013 - Vaadin componentizationSoftShake 2013 - Vaadin componentization
SoftShake 2013 - Vaadin componentization
Nicolas Fränkel
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
Yoav Farhi
 

Similaire à Creating Dynamic Sidebars & Widgets in WordPress (20)

WordPress Theme Workshop: Sidebars
WordPress Theme Workshop: SidebarsWordPress Theme Workshop: Sidebars
WordPress Theme Workshop: Sidebars
 
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
Tutorial, Part 4: SharePoint 101: Jump-Starting the Developer by Rob Windsor ...
 
(ATS4-DEV08) Building Widgets for the Symyx Notebook Home Page
(ATS4-DEV08) Building Widgets for the Symyx Notebook Home Page(ATS4-DEV08) Building Widgets for the Symyx Notebook Home Page
(ATS4-DEV08) Building Widgets for the Symyx Notebook Home Page
 
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
Advanced SharePoint 2010 and 2013 Web Part Development by Rob Windsor - SPTec...
 
Writing your own WordPress themes and plugins
Writing your own WordPress themes and pluginsWriting your own WordPress themes and plugins
Writing your own WordPress themes and plugins
 
Google web toolkit web conference presenation
Google web toolkit web conference presenationGoogle web toolkit web conference presenation
Google web toolkit web conference presenation
 
Wordpress Widgets type
Wordpress Widgets typeWordpress Widgets type
Wordpress Widgets type
 
Parallelminds.web partdemo1
Parallelminds.web partdemo1Parallelminds.web partdemo1
Parallelminds.web partdemo1
 
SoftShake 2013 - Vaadin componentization
SoftShake 2013 - Vaadin componentizationSoftShake 2013 - Vaadin componentization
SoftShake 2013 - Vaadin componentization
 
Twitter bootstrap (css, components and javascript)
Twitter bootstrap (css, components and javascript)Twitter bootstrap (css, components and javascript)
Twitter bootstrap (css, components and javascript)
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
 
Parallelminds.web partdemo
Parallelminds.web partdemoParallelminds.web partdemo
Parallelminds.web partdemo
 
Asp.Net MVC 5 in Arabic
Asp.Net MVC 5 in ArabicAsp.Net MVC 5 in Arabic
Asp.Net MVC 5 in Arabic
 
WordPress Theme Workshop: Widgets
WordPress Theme Workshop: WidgetsWordPress Theme Workshop: Widgets
WordPress Theme Workshop: Widgets
 
Mobile Application Development class 006
Mobile Application Development class 006Mobile Application Development class 006
Mobile Application Development class 006
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
 
16 asp.net session23
16 asp.net session2316 asp.net session23
16 asp.net session23
 
Android layouts course-in-mumbai
Android layouts course-in-mumbaiAndroid layouts course-in-mumbai
Android layouts course-in-mumbai
 
Rotating Banner in SharePoint with a DataView Webpart
Rotating Banner in SharePoint with a DataView WebpartRotating Banner in SharePoint with a DataView Webpart
Rotating Banner in SharePoint with a DataView Webpart
 
WordPress-like plugins for Next.js - Sanket Sahu
WordPress-like plugins for Next.js - Sanket SahuWordPress-like plugins for Next.js - Sanket Sahu
WordPress-like plugins for Next.js - Sanket Sahu
 

Plus de Jason Yingling

Plus de Jason Yingling (11)

WordPress Security Best Practices
WordPress Security Best PracticesWordPress Security Best Practices
WordPress Security Best Practices
 
Installing WP-CLI locally
Installing WP-CLI locallyInstalling WP-CLI locally
Installing WP-CLI locally
 
Getting Started with Gutenberg Development
Getting Started with Gutenberg DevelopmentGetting Started with Gutenberg Development
Getting Started with Gutenberg Development
 
Plugin development
Plugin developmentPlugin development
Plugin development
 
Introducing CSS Grid
Introducing CSS GridIntroducing CSS Grid
Introducing CSS Grid
 
Customizing the WordPress Customizer
Customizing the WordPress CustomizerCustomizing the WordPress Customizer
Customizing the WordPress Customizer
 
Battling Google PageSpeed Insights
Battling Google PageSpeed InsightsBattling Google PageSpeed Insights
Battling Google PageSpeed Insights
 
Putting the Develop in Development
Putting the Develop in Development Putting the Develop in Development
Putting the Develop in Development
 
WordPress Template hierarchy
WordPress Template hierarchyWordPress Template hierarchy
WordPress Template hierarchy
 
Design todevelop
Design todevelopDesign todevelop
Design todevelop
 
Building Flexible Sites with Advanced Custom Fields
Building Flexible Sites with Advanced Custom FieldsBuilding Flexible Sites with Advanced Custom Fields
Building Flexible Sites with Advanced Custom Fields
 

Dernier

pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
JOHNBEBONYAP1
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
gajnagarg
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Monica Sydney
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
pxcywzqs
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
F
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
F
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
ydyuyu
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
ayvbos
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Monica Sydney
 

Dernier (20)

Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
 
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
20240509 QFM015 Engineering Leadership Reading List April 2024.pdf
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 

Creating Dynamic Sidebars & Widgets in WordPress

  • 1. Dynamic Sidebars and Widgets Jason Yingling Red8 Interactive
  • 2. What is a sidebar? • Sidebar can mean two things: • An area to the side (but not always) of a post generally containing information tangentially related to the main content. • Generally a themes sidebar.php
  • 3. What is a sidebar? • An area where widgets can be used within a theme. Also known as a widgetized area. • Created by using the register_sidebar() function • Not strictly relegated to being used in sidebar.php. Also commonly used in footers.
  • 4. What is a widget? • Bits of code that can be used in a widgetized area to add functionality to WordPress sites.
  • 5. Registering (Creating) a Widgetized Area • Widgetized areas should be registered in the theme as they are presentational. Generally in functions.php. • Widgetized area can be displayed in any template file. Not tied to sidebar.php. • register_sidebar($args) creates the widgetized area • add_action( ‘widgets_init’, $function) hooks into WordPress to create a widgetized area when WordPress initializes the widgets.
  • 6. register_sidebar() • Takes a single argument of an associative array of parameters that set the options for the widget area. • Wrap $args array and register_sidebar() in separate function that can be called on ‘widgets_init’ hook
  • 7. add_action(‘widgets_init’, ‘function_name’); • Action hook in WordPress for connecting to the widget initialization function • Call previously defined function for registering a sidebar as second parameter • Allows WordPress to create the widget area in the backend.
  • 8.
  • 9. Displaying a Widgetized Area • is_active_sidebar(‘widget_id’) – Checks to see if the sidebar has any widgets activated. (optional) • dynamic_sidebar(‘widget_id’) – Displays the widgetized area and any widgets set inside it. • Can be used within any template files.
  • 10. Creating a Widget • Custom widgets are created by a class that extends the WP_Widget class. • Widget is initiated by hooking register_widget() into the ‘widgets_init’ action hook
  • 11. Extending the WP_Widget class • By extending the WP_Widget class we can add methods for our widget to use, as well as use methods and properties present in the WP_Widget class.
  • 12. Constructing our Widget • To construct our widget we use the parent __construct function from the WP_Widget class which takes 3 parameters – ‘widget-id’ : The id / slug of the widget – ‘Widget Name’ : The nice name to show on the admin screen – array() : An array of additional options
  • 14. Displaying Widget Content • To display the content of our widget we use the widget() method • widget() ‘echo’s a string wherever the widget is placed on your site • Takes two arguments: – $args – Widget arguments – $instance – Previously saved data in the database
  • 16. Creating a Form for Editing Widget Content • The form() method allows us to create HTML form elements for storing data within the widget • Uses the $instance argument to store data for the instance of the widget
  • 17. Creating a Form for Editing Widget Content
  • 18. Saving Widget Data • To save the widget $instance we’ll use the update() method • Takes two arguments: $new_instance and $old_instance • $new_instance will contain the new values entered in the widget’s form • $old_instance will contain the previous values, which are replaced with the $new_instance on aving the form
  • 20.
  • 21. Registering the Widget • Create a function to hold our register_widget(‘Widget_Class’) function • Hook in our newly created function into the ‘widgets_init’ action hook

Notes de l'éditeur

  1. The main thing to note here is we’ll be defining this as a widgetized area, but we use register_sidebar() to create the widgetized area.
  2. Name : the name for the widget area that shows in the admin area Description: A brief description of the widget area. Also shows in admin area. Id: the “slug” version of the widget area. Used to pull widget area in code. Class: CSS class that the widget area will take, ONLY IN ADMIN AREA Before_widget and after_widget: Provide HTML markup to wrap each individual widget used in the widget area. %1$s and %2$s pull in ID and class data from the widget’s registration code. Before_title and after_title: Provides the markup to wrap a Widget’s title.
  3. Show Code
  4. Good idea to use is_active_sidebar within an if statement so we only return the dynamic sidebar if it has an active widget in it. Show example of code within sidebar.php and index.php
  5. get_field_name and get_field_id look in the $instance to retrieve the form name and id tied to this widgets instance. http://codex.wordpress.org/Function_Reference/get_field_name