Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rodrigophpweb/ae4c431deee0c189b055929adfb5d2d1 to your computer and use it in GitHub Desktop.
Save rodrigophpweb/ae4c431deee0c189b055929adfb5d2d1 to your computer and use it in GitHub Desktop.
Data Structure WP
<?php
$terms = get_queried_object();
// Verify what Term selected
//$whatTerm = get_the_terms(get_the_ID(), 'evento');
$term = get_term('evento');
if(is_front_page()){
//Load Images
$img_single = get_field('image_event', $term);
$facedes = get_field('schools', $term);
}else{
$img_single = get_field('image_event', $term);
$facedes = get_field('schools', $term);
}
$loadImage = $img_single ? $img_single['sizes']['hero'] : get_the_post_thumbnail_url($facedes, 'hero');
$type_page = $loadImage ? $loadImage : get_the_post_thumbnail_url(get_the_ID(), 'hero');
// Date Initial and Final
$date_initial = str_replace("/", '-', get_field('initial_date', $term));
$convert_day_initial = date('Y-m-d', strtotime($date_initial));
$date_end = str_replace("/", '-', get_field('end_date', $term));
$convert_day_end = date('Y-m-d', strtotime($date_end));
// Arguments for the metas.
$args = [
'title' => get_bloginfo('name'),
'title_page' => get_the_title(),
'description' => $description = is_front_page() ? get_bloginfo('description') : wp_trim_words( get_the_content(), 150, '...'),
'url' => 'https://eventos.sp.senac.br',
'og_locale' => 'pt_BR',
'og_site_name' => get_bloginfo('name'),
'image' => $type_page,
'published_time' => get_the_date( 'Y-m-d\TG:i:s' ).'+00:00',
'modified_time' => get_the_modified_date( 'Y-m-d\TG:i:s' ).'+00:00',
];
if(is_tax('evento')):
$term = get_queried_object();
$image = get_field('image_event', $term);
$schools = get_field('schools', $term);
$termSlug = wp_trim_words($term->slug, 160, '...');
$termTitle = $term->name;
$termDescription = $term->description;
//Image variables.
$url = $image['url'];
$title = $image['title'];
$alt = $image['alt'];
$caption = $image['caption'];
//Thumbnail size attributes.
$size = 'hero';
$thumb = $image['sizes'][ $size ];
$width = $image['sizes'][ $size . '-width' ];
$height = $image['sizes'][ $size . '-height' ];
// Date Initial and Final
$date_initial = str_replace("/", '-', get_field('initial_date', $term));
$convert_day_initial = date('Y-m-d', strtotime($date_initial));
$date_end = str_replace("/", '-', get_field('end_date', $term));
$convert_day_end = date('Y-m-d', strtotime($date_end));
//Load Images
$img_single = get_field('image_event', $term);
$facedes = get_field('schools', $term);
$loadImage = $img_single ? $img_single['sizes']['card_front'] : get_the_post_thumbnail_url($facedes[0], 'card_front');
$type_page = $loadImage ? $loadImage : get_the_post_thumbnail_url(get_the_ID(), 'hero');
?>
<meta name="description" content="<?php echo $termDescription;?>" />
<meta name="robots" content="max-image-preview:large">
<meta property="og:locale" content="pt_BR" />
<meta property="og:site_name" content="Eventos Senac São Paulo" />
<meta property="og:type" content="article" />
<meta property="og:title" content="<?php echo $termTitle;?> - Eventos Senac São Paulo" />
<meta property="og:description" content="<?php echo $termDescription; ?>" />
<meta property="og:url" content="<?php echo 'https://eventos.sp.senac.br/evento/'.$termSlug;?>/" />
<meta property="og:image" content="<?php echo 'https://eventos.sp.senac.br'.$loadImage;?>" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@senacsaopaulo" />
<meta name="twitter:domain" content="sp.senac.br" />
<meta name="twitter:title" content="<?php echo $termTitle;?> - Eventos Senac São Paulo" />
<meta name="twitter:description" content="<?php echo $termDescription;?>" />
<meta name="twitter:creator" content="@senacsaopaulo" />
<meta name="twitter:image" content="<?php echo 'https://eventos.sp.senac.br'.$loadImage?>" />
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Event",
"name": "<?php echo $term->name;?>",
"description": "<?php echo $term->description;?>",
"startDate" : "<?php echo $convert_day_initial?>",
"endDate" : "<?php echo $convert_day_end?>",
"eventStatus": "https://schema.org/EventScheduled",
"eventAttendanceMode": "https://schema.org/OnlineEventAttendanceMode",
"image": [
"<?php
if($url) {
echo $url;
} else {
echo get_the_post_thumbnail_url($schools[0], 'full');
}
?>"
],
"organizer": {
"@type": "Organization",
"name": "Senac São Paulo",
"url": "https://eventos.sp.senac.br"
},
"location": {
"@type": "VirtualLocation",
"url": "https://eventos.sp.senac.br/evento/<?php echo $term->slug;?>?utm_campaign=Google_Eventos&utm_source=Google_Events&utm_medium=link"
},
"performer": {
"@type": "Organization",
"name": "Senac São Paulo"
},
"offers": {
"@type": "Offer",
<?php
$ticket = get_field('ticket_type');
if($ticket['value'] == 'gratuito'):
?>
"price": "0",
<?php else:?>
"price": "<?php the_field('price_ticket');?>",
<?php endif;?>
"priceCurrency": "BRL",
"availability": "https://schema.org/InStock",
"validFrom": "<?php echo $convert_day_end?>",
"url": "https://eventos.sp.senac.br/evento/<?php echo $term->slug;?>?utm_campaign=Google_Eventos&utm_source=Google_Events&utm_medium=link"
}
}
{
"@context": "https://schema.org",
"@type": "Organization",
"url": "https://www.sp.senac.br",
"logo": "https://www.sp.senac.br/o/senac-theme/images/logo_senac_default.png"
}
</script>
<?php
elseif(is_singular('events')):
$term = get_the_terms(get_the_ID(), 'evento');
$img_single = get_field('image_event', $term[0]);
$facedes = get_field('schools', $term[0]);
//Dia da atividade
$task_day = str_replace("/", '-', get_field('task_day'));
$convert_task_day = date('Y-m-d', strtotime($task_day));
//Fim da atividade
$end_task = str_replace("/", '-', get_field('end_task'));
$convert_end_task = date('Y-m-d', strtotime($end_task));
$date_day = date('Y-m-d');
$event_type = get_field('event_type');
$address_school = get_field('address_school');
$schools = get_field('unidades');
//Info
$link = get_the_permalink(get_the_ID());
$description = wp_trim_words(get_the_content(), 160, '...');
$title = get_the_title().' - Eventos Senac São Paulo';
$publish_time = get_the_date('Y-m-d');
$modified_time = get_the_modified_date('Y-m-d');
$domain = 'https://eventos.sp.senac.br';
$loadImage = $img_single ? $img_single['sizes']['hero'] : get_the_post_thumbnail_url($facedes[0], 'hero');
$courses = get_field('linksrel');
?>
<link rel="canonical" href="<?php echo $link;?>" />
<meta name="description" content="<?php echo $description;?>" />
<meta name="robots" content="max-image-preview:large" />
<meta property="og:locale" content="pt-BR" />
<meta property="og:site_name" content="Eventos Senac São Paulo" />
<meta property="og:type" content="activity" />
<meta property="og:title" content="<?php echo $title;?>" />
<meta property="og:description" content="<?php echo $description;?>" />
<meta property="og:url" content="<?php echo $link;?>" />
<meta property="og:image" content="<?php echo $loadImage;?>" />
<meta property="article:publisher" content="https://www.facebook.com/senacsaopaulo" />
<meta property="article:published_time" content="<?php echo $publish_time;?>" />
<meta property="article:modified_time" content="<?php echo $modified_time;?>" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@senacsaopaulo" />
<meta name="twitter:domain" content="https://eventos.sp.senac.br" />
<meta name="twitter:title" content="<?php echo $title;?>" />
<meta name="twitter:description" content="<?php echo $description?>" />
<meta name="twitter:creator" content="@senacsaopaulo" />
<meta name="twitter:image" content="<?php echo $loadImage;?>" />
<meta name="twitter:label1" content="Written by" />
<meta name="twitter:data1" content="Senac São Paulo" />
<script type="application/ld+json">
{
"@context" : "http://schema.org",
"@type" : "Event",
"name" : "<?php the_title();?>",
<?php if(get_field('end_task') == get_field('task_day') || get_field('end_task') == '') :?>
"startDate" : "<?php echo $convert_task_day;?>T<?php echo get_field('hour_initial')?>-03:00",
"endDate" : "<?php echo $convert_task_day;?>T<?php echo get_field('hour_initial')?>-03:00",
<?php else:?>
"startDate" : "<?php echo $convert_task_day;?>T<?php echo get_field('hour_initial')?>-03:00",
"endDate" : "<?php echo $convert_end_task;?>T<?php echo get_field('hour_initial')?>-03:00",
<?php endif;?>
<?php if($event_type['value'] == 'online'):?>
"eventAttendanceMode": "https://schema.org/OnlineEventAttendanceMode",
<?php else:?>
"eventAttendanceMode": "https://schema.org/OfflineEventAttendanceMode",
<?php endif;?>
"eventStatus": "https://schema.org/EventScheduled",
"location" : {
<?php if($event_type['value'] == 'online'):?>
"@type" : "VirtualLocation",
"url" : "https://eventos.sp.senac.br<?php the_permalink();?>?utm_campaign=Google_Eventos&utm_source=Google_Events&utm_medium=link"
<?php
else:
$parts = explode(",", $address_school['label']);
$local = explode('-', $parts[2]);
?>
"@type": "Place",
<?php
$location_event = get_field('location_event');
$location_extern = get_field('location_extern');
if($location_event['value'] == 'fora'):
$separteLocationExtern = explode(",", $location_extern);
?>
"name": "<?php $nameExtern = explode(" ", $location_extern); echo $nameExtern[0].' '.$nameExtern[1];?>",
"address": {
"@type": "PostalAddress",
"streetAddress": "<?php echo $separteLocationExtern[1].', '.$separteLocationExtern[2];?>",
"addressLocality": "<?php echo $separteLocationExtern[3];?>",
"postalCode": "<?php echo $separteLocationExtern[5];?>",
"addressRegion": "SP",
"addressCountry": "BR"
}
<?php else:?>
"name": "<?php echo get_the_title($schools);?>",
"address": {
"@type": "PostalAddress",
"streetAddress": "<?php echo get_field('streetAddress',$schools).' - '.get_field('district_school', $schools);?>",
"addressLocality": "<?php the_field('addressLocality', $schools);?>",
"postalCode": "<?php the_field('postalCode', $schools);?>",
"addressRegion": "SP",
"addressCountry": "BR"
}
<?php endif;?>
<?php endif;?>
},
"image" : "<?php echo 'https://eventos.sp.senac.br'.$loadImage;?>",
"description" : "<?php echo wp_strip_all_tags(get_the_excerpt());?>",
"url" : "https://eventos.sp.senac.br<?php the_permalink();?>?utm_campaign=Google_Eventos&utm_source=Google_Events&utm_medium=link",
"performer" :
[
<?php
$posts_speakers = get_field('posts_speakers');
if($posts_speakers):
$result = count($posts_speakers);
foreach($posts_speakers as $index => $post):
setup_postdata($post);
if ($index === array_key_last($posts_speakers)) :
?>
{
"@type" : "Person",
"name" : "<?php echo get_the_title($post);?>"
}
<?php elseif($result === 1):?>
{
"@type" : "Person",
"name" : "<?php echo get_the_title($post);?>"
}
<?php else:?>
{
"@type" : "Person",
"name" : "<?php echo get_the_title($post);?>"
},
<?php endif;
endforeach; wp_reset_postdata();
endif;
?>
],
<?php
$typeticket = get_field('ticket_type');
if($typeticket['value'] == 'gratuito' ):
?>
"offers" : {
"@type" : "Offer",
"price" : "0",
"availability": "https://schema.org/InStock",
<?php
$offer = get_field('offer');
if($offer['value'] == 'senac'):
?>
"url": "https://www.sp.senac.br/login/Login?destino=https://www.sp.senac.br/ecommerceFrontEnd/?vcw_unidade=<?php the_field('school_offer');?>&vcw_evento=<?php the_field('codigo_ss')?>&utm_campaign=Google_Eventos&utm_source=Google_Events&utm_medium=link",
<?php else:?>
"url": "<?php the_field('offer_url');?>?utm_campaign=Google_Eventos&utm_source=Google_Events&utm_medium=link",
<?php endif;?>
"priceCurrency": "BRL",
<?php else:?>
"offers" : {
"@type" : "Offer",
"availability": "https://schema.org/InStock",
<?php
$offer = get_field('offer');
if($offer['value'] == 'senac'):
?>
"url": "https://www.sp.senac.br/login/Login?destino=https://www.sp.senac.br/ecommerceFrontEnd/?vcw_unidade=<?php the_field('school_offer');?>&vcw_evento=<?php the_field('codigo_ss')?>&utm_campaign=Google_Eventos&utm_source=Google_Events&utm_medium=link",
<?php else:?>
"url": "<?php the_field('offer_url');?>?utm_campaign=Google_Eventos&utm_source=Google_Events&utm_medium=link",
<?php endif;?>
"price" : "<?php the_field('price_ticket')?>",
"priceCurrency": "BRL",
<?php endif;?>
<?php if(get_field('end_task') == get_field('task_day') || get_field('end_task') == '') :?>
"validFrom" : "<?php echo $convert_day_end;?>T<?php echo get_field('hour_final')?>"
<?php else:?>
"validFrom" : "<?php echo $convert_end_task;?>T<?php echo get_field('hour_final')?>"
<?php endif;?>
},
"organizer": {
"@type": "Organization",
"name": "Senac São Paulo",
"url": "https://www.sp.senac.br"
}
}
{
"@context": "https://schema.org",
"@type": "Organization",
"url": "https://www.sp.senac.br",
"logo": "https://www.sp.senac.br/o/senac-theme/images/logo_senac_default.png"
}
</script>
<?php
elseif(is_singular('unidades')):
$link = get_the_permalink(get_the_ID());
$title = get_the_title().' - Eventos Senac São Paulo';
$textDescription = get_the_content() ? get_the_content() : 'Saiba mais sobre os eventos da unidade '.$title.'. Nessa página você encontra os próximos eventos e eventos anteriores da unidade';
$description = wp_trim_words($textDescription, 160, '...');
$publish_time = get_the_date('Y-m-d');
$modified_time = get_the_modified_date('Y-m-d');
$domain = 'https://eventos.sp.senac.br';
$loadImage = get_the_post_thumbnail_url(get_the_ID(), 'hero');
?>
<link rel="canonical" href="<?php echo $link;?>" />
<meta name="description" content="<?php echo $description;?>" />
<meta name="robots" content="max-image-preview:large" />
<meta property="og:locale" content="pt-BR" />
<meta property="og:site_name" content="Eventos Senac São Paulo" />
<meta property="og:type" content="activity" />
<meta property="og:title" content="<?php echo $title;?>" />
<meta property="og:description" content="<?php echo $description;?>" />
<meta property="og:url" content="<?php echo $link;?>" />
<meta property="og:image" content="<?php echo $loadImage;?>" />
<meta property="article:publisher" content="https://www.facebook.com/senacsaopaulo" />
<meta property="article:published_time" content="<?php echo $publish_time;?>" />
<meta property="article:modified_time" content="<?php echo $modified_time;?>" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@senacsaopaulo" />
<meta name="twitter:domain" content="https://eventos.sp.senac.br" />
<meta name="twitter:title" content="<?php echo $title;?>" />
<meta name="twitter:description" content="<?php echo $description?>" />
<meta name="twitter:creator" content="@senacsaopaulo" />
<meta name="twitter:image" content="<?php echo $loadImage;?>" />
<meta name="twitter:label1" content="Written by" />
<meta name="twitter:data1" content="Senac São Paulo" />
<?php elseif(is_front_page()):
include(locate_template('inc/metas.php'));?>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Organization",
"url": "https://www.sp.senac.br",
"logo": "https://www.sp.senac.br/o/senac-theme/images/logo_senac_default.png"
}
{
"@context": "https://schema.org",
"@type": "WebSite",
"url": "https://eventos.sp.senac.br",
"potentialAction": {
"@type": "SearchAction",
"target": {
"@type": "EntryPoint",
"urlTemplate": "https://eventos.sp.senac.br/?s={search_term_string}"
},
"query-input": "required name=search_term_string"
}
}
</script>
<?php elseif(is_page()):
include(locate_template('inc/metas.php'));
else:?>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Organization",
"url": "https://www.sp.senac.br",
"logo": "https://www.sp.senac.br/o/senac-theme/images/logo_senac_default.png"
}
{
"@context": "https://schema.org",
"@type": "WebSite",
"url": "https://eventos.sp.senac.br",
"potentialAction": [
{
"@type": "SearchAction",
"target": {
"@type": "EntryPoint",
"urlTemplate": "https://eventos.sp.senac.br/?s={search_term_string}"
},
"query-input": "required name=search_term_string"
},
{
"@type": "SearchAction",
"target": {
"@type": "EntryPoint",
"urlTemplate": "https://eventos.sp.senac.br/?s={search_term_string}"
},
"query-input": "required name=search_term_string"
}
]
}
</script>
<?php endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment