Forum
Gallery album social sharing image.
I'm attempting to pull an image from the album.php page into page attributes for social media sharing, without success.
The template code for the image I'm after is thus:
<perch:gallery id="image" type="image" key="two" width="1600" />
I placed the following in a page attributes file to no avail.
<meta property="og:image" content="<perch:pages id="domain" /><perch:gallery id="two" />" />
I've also unsuccessfully tried the following:
This in a header.php file (just showing the relevant bits here);
<?php
$domain = 'https://'.$_SERVER["HTTP_HOST"];
$sharing_image = perch_gallery_image(perch_get('id'), array(
'skip-template' => 'true',
),true);
PerchSystem::set_var('domain',$domain);
PerchSystem::set_var('sharing_image',$sharing_image);
?>
Then this in a page attributes file;
<meta property="og:image" content="<perch:pages id="domain" /><perch:pages id="sharing_image" />" />
Still trying to figure this out myself but would appreciate any pointers. Thanks.
If you break it down, which part isn't working?
Hi Drew. Seems to me the problem is here as I get a result when I hard code an id without the array, though the result is echoed onto the page though and doesn't transfer to the variable. Apologies if this is ovbious, having a sub-optimal day.
What's the value of
id
on your query string?It's /gallery/album.php?s=gallery-one. I'm using a slider so I'm outputting all the images in an album to the page with;
Should I be/can I use that to retrive a single image from the album?
Yes, you should be able to set a
count
in the options to reduce it to one item.Great, that's fixed it.
In case it's useful to anyone, header code is;
Gallery sharing-image.html template is just;
Thanks Drew