Page 1 of 1

Fetch Cover Image in Plugin (Solved)

Posted: Wed Feb 14, 2024 5:31 am
by rizqijune
How to fetch cover image in plugin?

It's working in my page.php theme. But in plugin it is not generating anything. I tried to add "test" to src image to make sure.
Am I missing something?

This is my plugin.php

Code: Select all

public function showFeatured()
	{
		global $L;
		global $pages;
		global $Page;
		
	
		if ($this->getValue('featured') == true) {
			include ($this->phpPath().'php/components/featured.php');
		} else {
			$html = "false";
		}
		return $html;
	}
and this is my featured.php

Code: Select all

<?php
$stickyPageKeys = $pages->getStickyDB();
foreach ($stickyPageKeys as $pageKey):
    $page = new Page($pageKey);
    $title = $page->title();
    $link = $page->permalink();
    $img = $page->coverImage();
    $items = file_get_contents(PATH_PAGES . $pageKey . DS . FILENAME);
?>
    <li class="splide__slide" style="height: 13rem;">
        <a href="<?php echo $link; ?>">
            <img src="<?php echo $img; ?> test"
                 style="display: block; -o-object-fit: cover; object-fit: cover; -o-object-position: center; object-position: center; width: 100%; height: 13rem;"
                 alt="<?php echo $title . ' image'; ?>">
        </a>
    </li>
<?php endforeach; ?>
Tell me if you need more informations
  • Version : Bludit 3.15.0
  • PHP : PHP 8.2
  • Theme : Riztail (My theme project)
  • Plugin : Default Starter Plugin and custom theme plugin ($themePlugin)
  • Javascript : Splide Carousel JS Version 4.1.4
Screenshot :
Image
Image
I dont post my full code to make this post easier to read :D

Re: Fetch Cover Image in Plugin

Posted: Thu Feb 15, 2024 12:08 pm
by rizqijune
My bad. I forgot to add the cover image for the sticky content! :lol: