]> git.bts.cx Git - cx.git/commitdiff
Don't break when there's no hero image
authorBen Sherratt <redacted>
Sun, 19 Nov 2023 16:33:09 +0000 (16:33 +0000)
committerBen Sherratt <redacted>
Sun, 19 Nov 2023 16:33:09 +0000 (16:33 +0000)
cx/lib/posts.php
cx/templates/public/base.php

index 2c2dc821e811bfc0fe94d66823a28f0af7940ce3..0a2ac4d997ff9c5133c0c0a27cffc6e4ee376f9e 100644 (file)
@@ -15,8 +15,8 @@ class PostMetadata {
        public $hero_image_alt;
 
        public function __construct($dict) {
-               $this->hero_image = $dict['post_hero_image'];
-               $this->hero_image_alt = $dict['post_hero_image_alt'];
+               $this->hero_image = isset($dict['post_hero_image']) ? $dict['post_hero_image'] : null;
+               $this->hero_image_alt = isset($dict['post_hero_image_alt']) ? $dict['post_hero_image_alt'] : null;
        }
 }
 
index d031247a2463a16dec049b55ca6858141615afd4..f5e96705717a3affa791166a1675b54b0d9b3213 100644 (file)
        
        <meta property="og:title" content="<?= cx_site_name(); ?> - <?= $cx_post_title; ?>">
        <meta property="og:type" content="article" />
+
+       <?php if (isset($cx_post_meta->hero_image)): ?>
        <meta property="og:image" content="<?= $cx_post_meta->hero_image; ?>">
+       <?php endif; ?>
+
        <meta property="og:url" content="<?= cx_url_site($cx_post_permalink); ?>">
        <meta name="twitter:card" content="summary_large_image">
+
+       <?php if (isset($cx_post_meta->hero_image_alt)): ?>
        <meta name="twitter:image:alt" content="<?= $cx_post_meta->hero_image_alt; ?>">
+       <?php endif; ?>
 
        <?php /*<meta property="og:description" content="Offering tour packages for individuals or groups.">
        <meta property="og:site_name" content="<?= cx_site_name(); ?>">