Using the Item Showcase code to display linked resources of an item

Hello,
I am adapting an Omeka-S theme, and would like to adjust the show.phtml file to display the linked resources of an item the same way it does the item showcase block. I found the item showcase code and am trying to integrate it into the phtml page

        <div class="twothirds">
          <div class="item-showcase">
          <?php foreach ($attachments as $attachment): ?>
              <div class="item resource">
              <?php
              $item = $resource->item();
              if ($item):
              ?>
                  <?php
                  $media = $attachment->media() ?: $item->primaryMedia();
                  if ($media):
                      echo $item->linkRaw($this->thumbnail($media, $this->thumbnailType));
                  endif;
                  ?>
                  <?php $showTitleOption = $this->showTitleOption; ?>
                  <?php if ($showTitleOption == 'item_title'): ?>
                  <h3><?php echo $item->link($item->displayTitle()); ?></h3>
                  <?php elseif ($showTitleOption == 'file_name'): ?>
                  <h3><?php echo $media->displayTitle(); ?></h3>
                  <?php endif; ?>
              <?php endif; ?>

              <?php
              $caption = $attachment->caption();
              if ($caption):
              ?>
                  <div class="caption"><?php echo $caption; ?></div>
              <?php endif; ?>
              </div>
          <?php endforeach; ?>
          </div>
        </div>

I imagine that i need to at least being with changing the line

<?php foreach ($attachments as $attachment): ?>

to be something like foreach linked item to this item with certain conditions (such as select every item that is an image that is linked to this image in this particular field)…and then each of those to be displayed as the thumbnail with the link.

However I am not sure how to call the related items. I tried to look at the DisplaySubjectValues but can’t figure it out. Any guidance would be appreciated.

Do you want to display in this way other items that link to the current item, or ones that the current item links out to?

I think other items that link to the other item.
For example the main item on the page is a Theatre Production, and I want to link all the images that are of that Theatre Production (in the image resource there is a field called superevent which is a linked Omeka resource).
Thanks and hope that clarifies,
Sanjin

OK, so yes it sounds like you want items linking to the current one.

You can do $item->subjectValues() to get an array of all the values that link to $item. For each of those values, you can do $relatedResource = $value->resource(); to get the resource that’s linking in.

Then you should be able to pretty much use the “showcase” code but with $relatedResource standing in for the use of $item in that snippet you posted. There’s also other bits of code like the if blocks dealing with options of the Showcase block and you’ll have to deal with those as well, since there’s no block and therefore no options here.

1 Like

DearJflatnes,

I am going to have to ask for you to break it down for me a bit more, as i am new to php and am trying to figure out how Omeka works in the backend.
I have tried to follow what i understood from what you said:

        $linkeditemsarray = $item->subjectValues();
        php foreach ($linkeditemsarray as $value):
            $relatedResource = $value->resource();?>

But with this I get a Call to a member function resource() on array error. From what you said if linkeditemsarray is all the items that link to this item, then going through it should allow me to use your code to create the variable for each one in $relatedResource. Or is linkeditemsarry an array of arrays with all the information of the linked items.
I am trying to build a theme that alters the show item page based on the resource element of the item, so any documentation that you have around how to call the various functions to be able to access the resources of the item. I tried to look at Representations - Omeka S Developer Documentation but am not clever enough to figure it out at this point in time (maybe with experience).
Thanks for your time

The issue here is just that subjectValues() gives you a nested array back: it’s an array of arrays (each one the values for one property), so you just need another “level” of foreach.

Yes! Got it. More levels was the answer.
Thank you.
Thank you.
THANK you.

The code ended up looking something like this:

        <div class="twothirds">
          <?php $linkeditemsarray = $item->subjectValues();
            foreach ($linkeditemsarray as $linkeditem):
            ?>
          <div class="item-showcase">
          <?php foreach ($linkeditem as $value):
            $relatedResource = $value->resource();?>
              <div class="item resource">
                  <?php
                  $media = $relatedResource->primaryMedia();
                  //if ($media):
                  //    echo $relatedResource->linkRaw($this->thumbnail($media, $this->thumbnailType));
                  //endif;
                  echo $relatedResource->linkRaw($this->thumbnail($relatedResource, 'medium',['alt'=>$relatedResource->displayTitle(),'class'=>'squareimage']), null, ['class' => 'squarecontainer']);?>
                  <h3><?php echo $relatedResource->link($relatedResource->displayTitle()); ?></h3>
              </div>
          <?php endforeach; ?>
          </div>
      <?php endforeach; ?>
        </div>
1 Like

A further development from this request. I would like to sort the list of items that link to this resource by their class, so that I can create a table each for Images/Audio/Videos, etc.

Something similar to the linked-resources.phtml code, but instead of grouping it by the property, rather to almost invert it, so that the list of resources that link to it is grouped by their class of the items.

What would be the method to do this? Many thanks.

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