Forum
Events and Page Attributes / meta
Hi,
I'm following along with your tutorial on “Using Page Attributes to add Facebook Open Graph Tags and Twitter Cards”.
https://solutions.grabaperch.com/integrations/facebook-and-twitter-sharing
Where I'm getting stuck is on the Events app, where nothing at all is showing in the head of my site. The handy 'perch_blog_post_meta(perch_get('s'));' is great. Is there nothing for Events that is equivalent? Do I have to rewrite templates that draw upon the events data myself?
<?php perch_layout('global-header');
# get the post
$event = perch_events_custom(array(
'filter' => 'eventSlug',
'match' => 'eq',
'value' => perch_get('s'),
'skip-template' => 'true',
'return-html' => 'true',
));
// echo '<pre>';
// var_dump($event);
// echo '</pre>';
# set up the variables
$domain = 'https://'.$_SERVER["HTTP_HOST"];
$title = $event['0']['eventTitle'];
$longdescription = strip_tags($event['0']['eventDescHTML']);
$description = substr($longdescription,0,157) . '...'; // Shorten the event HTML
if (isset($event[0]['fbimage'])) {
$fbimage = $event[0]['fbimage'];
} else {
$fbimage = $domain . '/perch/resources/' . $event['0']['image']['sizes']['w1200h630c1']['path'];
}
# use the variables in the array value
perch_page_attributes_extend(array(
'description' => $description,
'og_description' => $description,
'og_title' => $title,
'og_type' => 'article',
'sharing_image' => $fbimage,
'og_author' => 'https://www.facebook.com/myfbname',
));
perch_layout('endhead-startbody');?>
If I add 'hello' as a line of raw test into templates/pages/attributes/default.html nothing appears in the page source markup on blog or events, however it does in regular pages.
I can confirm that extra code for $fbimage works fine in generating the url.
If I var_dump $event, I see all the relevant information.
Can you please offer any advice on how to get the events meta to kick into gear?
Thanks!
All
perch_blog_post_meta()
does is callperch_blog_custom()
with a different default template. The concept is simply displaying your event through a template that outputs a subset of fields.OK So I'll simply knock up a template to that effect for Events then, thanks.
I see that the blog uses
So I'll re-use that when constructing the events version.