Conditional file display

I am trying to display in Public page of Omeka Classis 2.7 version only ‘pdf’ files for the items attached with a pdf file, and not the image files that are attached with other items.

This earlier post has provided a clue : Display only PDF files · Legacy Forums · Omeka

But naturally, this piece of code is giving error in Omeka 2.7 (I’m using PHP 7.4.18 (cli) (built: May 3 2021 11:26:29) ( NTS ), Zend Engine v3.4.0,).

Question is how can in a multiple types of files environment we display only PDFs to appear in public page (theme we are using is Rhythm).