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

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Recently uploaded (20)

[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

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; ?>