Show sites logos in site list

I’m building a theme for a page that contains a list of sites. I’d like to show the site logo for each of the sites in the list.

Is there a property I can access from my site-list-entry.phtml view that will give me the logo for the site in the list?

This code shows the logo for the current site:

<?php if ($this->themeSetting('logo')): ?>
   <img src="<?php echo $this->themeSettingAssetUrl('logo'); ?>" alt="<?php echo $escape($siteTitle); ?>" />
<?php endif; ?>

I’d like to do something like that, but for each individual site in the list to get their respective logos. Any way to accomplish this?

Hello Scott,

I’ve managed to get the logos on the site list entry this way:

In the first heading part of site-list-entry.phtml, you have to retrieve the theme containing the logo asset id:

$themeSettings = $this->siteSetting('theme_settings_' . $site->theme(), null, $site->id());

try {
    $response = $this->api()->read('assets', $themeSettings['logo']);
    $logoUrl = $response->getContent()->assetUrl();
} catch (Omeka\Api\Exception\NotFoundException $e) {
    $logoUrl = null;
}

Then you just have to display the logo image using the $logoUrl value.

Here is a basic example of a complet site-list-entry.phtml view file:

<?php
$summary = $showSummary ? $site->summary() : null;

$themeSettings = $this->siteSetting('theme_settings_' . $site->theme(), null, $site->id());

try {
    $response = $this->api()->read('assets', $themeSettings['logo']);
    $logoUrl = $response->getContent()->assetUrl();
} catch (Omeka\Api\Exception\NotFoundException $e) {
    $logoUrl = null;
}
?>
<div class="site">
    <?php if ($logoUrl): ?>
       <img src="<?php echo $logoUrl; ?>" alt="<?php echo $this->escapeHtml($site->title()); ?>" />
    <?php endif; ?>

    <?php echo $this->hyperlink($site->title(), $site->siteUrl(), ['class' => 'site-link']); ?>
    <?php if ($summary): ?>
    <p class="site-summary"><?php echo nl2br($this->escapeHtml($summary)); ?></p>
    <?php endif; ?>
</div>
2 Likes

Exactly what I was looking for. Thank you!

This topic was automatically closed 250 days after the last reply. New replies are no longer allowed.