SlideShare a Scribd company logo
1 of 21
Download to read offline
CREATING MICROSITES
A 1 DAY JOB DOWN TO 30 MINS
STEPH COOK
Who am I?
Software Engineer @ Magma Digital Ltd

Graduate from Comp Sci Manchester University

WordPress Core Contributor

!
!
!
@stephcook22 / +StephCook / stephcook.co.uk
THE OLD LISTING
1. Hope a category is already created

2. Create a new page

3. Copy an existing microsite layout and fill in the bits of content we need.

4. Figure out the category id (not easy!)

5. Create a new widget which only appears on that page showing all the posts in that
category using the id.

6. Create a new contact form with the correct details

7. Create the contact form widget which only appears on that page.

8. Add them to the supplier listing with logo, correct title and link to the microsite.
Setting up a Microsite
Why this is a bad solution
●
Very easy to miss steps

●
you need to repeat data a lot - this can cause mistakes

●
means there are a huge amount of categories

●
would be difficult to link back to things (e.g. from post to
microsite)

●
huge amount of widgets

●
each microsite was styled slightly differently since this was done
by hand

●
and it took a whole day...
Enter Custom Post Types!
Just like a normal post BUT…

●
make custom variables invisible

●
create your own interface

●
allow custom templates

●
separated in the admin panel
Creating a Custom Post Type
1 <?php
2 add_action( 'init', 'acme_create_post_type' );
3 function acme_create_post_type() {
4 register_post_type( 'acme_microsite',
5 array(
6 'labels' => array(
7 'name' => __( 'Microsites' ),
8 'singular_name' => __( 'Microsite' )
9 ),
10 'public' => true,
11 'has_archive' => true,
12 )
13 );
14 }
HOW CUSTOM POST TYPES APPEAR IN THE ADMIN PANEL
EDITING A STANDARD CUSTOM POST
Customising!
1 <?php
2 add_action('admin_init', 'acme_microsite_meta');
3 function acme_microsite_meta()
4 {
5 add_meta_box(
6 'contact_details',
7 'Contact Details',
8 'acme_add_contact_box_to_microsite',
9 'acme_microsite',
10 'side',
11 'low'
12 );
13 }
1 <?php
2 function acme_add_contact_box_to_microsite($object, $box ) {
3 wp_nonce_field(
4 basename(__FILE__),
5 'acme_microsite_contact_email_nonce'
6 );
7
8 $contact_email = esc_attr(
9 get_post_meta($object->ID, 'contact_email', true)
10 );
11 ?>
12
13 <p>
14 <label>
15 <?php _e('Contact Email (default:info@email.com):');?>
16 </label>
17 <br />
18
19 <input name="contact_email" value="<?php echo $contact_email ?>" />
20 </p>
21 <?php }
EDITING A CUSTOM POST WITH META DATA
1 <?php
2 add_action('save_post', 'acme_save_microsite', 10, 2 );
3
4 function acme_save_microsite($post_id)
5 {
6 if (
7 !isset( $_POST['contact_email'] ) ||
8 !wp_verify_nonce(
9 $_POST['acme_microsite_contact_email_nonce'],
10 basename( __FILE__ )
11 )
12 ) {
13 return $post_id;
14 }
15
16 if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
17 if ( ! current_user_can( 'edit_page', $post_id ) ) {
18 return $post_id;
19 }
20 } else {
21 if ( ! current_user_can( 'edit_post', $post_id ) ) {
22 return $post_id;
23 }
24 }
25
26 $email = sanitize_email($_POST['contact_email']);
27
28 update_post_meta($post_id, 'contact_email', $email);
29 }
Accessing the Meta Data
1 <?php
2 $post_class = get_post_meta( $post_id, 'contact_email', true );
POSTS 2 POSTS
Creating a Connection
1 <?php
2 function acme_add_connection_types() {
3 p2p_register_connection_type( array(
4 'name' => 'posts_to_microsites',
5 'from' => 'post',
6 'to' => 'acme_microsite'
7 ) );
8 }
9 add_action( 'p2p_init', 'acme_add_connection_types' );
POSTS 2 POSTS IN ACTION
Displaying Connected Posts
1 <?php
2 // Find connected pages
3 $connected = new WP_Query( array(
4 'connected_type' => 'posts_to_microsites',
5 'connected_items' => get_queried_object(),
6 'nopaging' => true,
7 ) );
8
9 // Display connected pages
10 if ( $connected->have_posts() ) : ?>
11 <h3>Related posts:</h3>
12 <ul>
13 <?php while ( $connected->have_posts() ) : $connected->the_post(); ?>
14 <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
15 <?php endwhile; ?>
16 </ul>
17
18 <?php
19 // Prevent weirdness
20 wp_reset_postdata();
21
22 endif; ?>
THE END PRODUCT
Thank you!
http://bit.ly/wc_microsites

!
!
@stephcook22 / +StephCook / stephcook.co.uk

More Related Content

Recently uploaded

Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Recently uploaded (20)

Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
Measures in SQL (a talk at SF Distributed Systems meetup, 2024-05-22)
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 

Featured

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software
 

Featured (20)

Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 

Creating Microsites: A 1 day job down to 30 mins

  • 1. CREATING MICROSITES A 1 DAY JOB DOWN TO 30 MINS STEPH COOK
  • 2. Who am I? Software Engineer @ Magma Digital Ltd Graduate from Comp Sci Manchester University WordPress Core Contributor ! ! ! @stephcook22 / +StephCook / stephcook.co.uk
  • 4.
  • 5. 1. Hope a category is already created 2. Create a new page 3. Copy an existing microsite layout and fill in the bits of content we need. 4. Figure out the category id (not easy!) 5. Create a new widget which only appears on that page showing all the posts in that category using the id. 6. Create a new contact form with the correct details 7. Create the contact form widget which only appears on that page. 8. Add them to the supplier listing with logo, correct title and link to the microsite. Setting up a Microsite
  • 6. Why this is a bad solution ● Very easy to miss steps ● you need to repeat data a lot - this can cause mistakes ● means there are a huge amount of categories ● would be difficult to link back to things (e.g. from post to microsite) ● huge amount of widgets ● each microsite was styled slightly differently since this was done by hand ● and it took a whole day...
  • 7. Enter Custom Post Types! Just like a normal post BUT… ● make custom variables invisible ● create your own interface ● allow custom templates ● separated in the admin panel
  • 8. Creating a Custom Post Type 1 <?php 2 add_action( 'init', 'acme_create_post_type' ); 3 function acme_create_post_type() { 4 register_post_type( 'acme_microsite', 5 array( 6 'labels' => array( 7 'name' => __( 'Microsites' ), 8 'singular_name' => __( 'Microsite' ) 9 ), 10 'public' => true, 11 'has_archive' => true, 12 ) 13 ); 14 }
  • 9. HOW CUSTOM POST TYPES APPEAR IN THE ADMIN PANEL
  • 10. EDITING A STANDARD CUSTOM POST
  • 11. Customising! 1 <?php 2 add_action('admin_init', 'acme_microsite_meta'); 3 function acme_microsite_meta() 4 { 5 add_meta_box( 6 'contact_details', 7 'Contact Details', 8 'acme_add_contact_box_to_microsite', 9 'acme_microsite', 10 'side', 11 'low' 12 ); 13 }
  • 12. 1 <?php 2 function acme_add_contact_box_to_microsite($object, $box ) { 3 wp_nonce_field( 4 basename(__FILE__), 5 'acme_microsite_contact_email_nonce' 6 ); 7 8 $contact_email = esc_attr( 9 get_post_meta($object->ID, 'contact_email', true) 10 ); 11 ?> 12 13 <p> 14 <label> 15 <?php _e('Contact Email (default:info@email.com):');?> 16 </label> 17 <br /> 18 19 <input name="contact_email" value="<?php echo $contact_email ?>" /> 20 </p> 21 <?php }
  • 13. EDITING A CUSTOM POST WITH META DATA
  • 14. 1 <?php 2 add_action('save_post', 'acme_save_microsite', 10, 2 ); 3 4 function acme_save_microsite($post_id) 5 { 6 if ( 7 !isset( $_POST['contact_email'] ) || 8 !wp_verify_nonce( 9 $_POST['acme_microsite_contact_email_nonce'], 10 basename( __FILE__ ) 11 ) 12 ) { 13 return $post_id; 14 } 15 16 if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) { 17 if ( ! current_user_can( 'edit_page', $post_id ) ) { 18 return $post_id; 19 } 20 } else { 21 if ( ! current_user_can( 'edit_post', $post_id ) ) { 22 return $post_id; 23 } 24 } 25 26 $email = sanitize_email($_POST['contact_email']); 27 28 update_post_meta($post_id, 'contact_email', $email); 29 }
  • 15. Accessing the Meta Data 1 <?php 2 $post_class = get_post_meta( $post_id, 'contact_email', true );
  • 17. Creating a Connection 1 <?php 2 function acme_add_connection_types() { 3 p2p_register_connection_type( array( 4 'name' => 'posts_to_microsites', 5 'from' => 'post', 6 'to' => 'acme_microsite' 7 ) ); 8 } 9 add_action( 'p2p_init', 'acme_add_connection_types' );
  • 18. POSTS 2 POSTS IN ACTION
  • 19. Displaying Connected Posts 1 <?php 2 // Find connected pages 3 $connected = new WP_Query( array( 4 'connected_type' => 'posts_to_microsites', 5 'connected_items' => get_queried_object(), 6 'nopaging' => true, 7 ) ); 8 9 // Display connected pages 10 if ( $connected->have_posts() ) : ?> 11 <h3>Related posts:</h3> 12 <ul> 13 <?php while ( $connected->have_posts() ) : $connected->the_post(); ?> 14 <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> 15 <?php endwhile; ?> 16 </ul> 17 18 <?php 19 // Prevent weirdness 20 wp_reset_postdata(); 21 22 endif; ?>