Custom Browse.php for Collections


I'm trying to customise the collections/browse/php on my theme but just cannot get it working the way I want at all.

I'm trying to filter out the collections by a certain metadata tag that I'm using.

So far I get it to hide all non relevenant collections and show the ones I want but the troiuble is it still adds the pagination as though the records were still being dislayed.

I tried adding an argument to the <?php foreach (loop('collections') as $collection): ?> to say if the field value is 'Yes' then olnly show these records but doesn't work, I think I'm the right track but must be getting the syntax wrong.

My code for browse.php is below:

$pageTitle = __('Browse Collections');
echo head(array('title'=>$pageTitle,'bodyid'=>'collections','bodyclass' => 'browse'));
<div id="primary">
    <h1><?php echo $pageTitle;?> (<?php echo total_records('Collection') ?>)</h1>

    <?php if (total_records('Collection')): ?>

    <?php foreach (loop('collections') as $collection): ?>

        $isOrganisation = metadata('collection', array('Dublin Core', 'Is Organisation'));
		if ($isOrganisation == 'Yes')


    <div class="collection">

        <h2><?php echo link_to_collection(); ?></h2>

        <?php if ($description = snippet_by_word_count(metadata('collection', array('Dublin Core', 'Description')), 50)): ?>
        <div class="description collection-description">
            <div class="element-text"><?php echo $description; echo link_to_collection('show more.');?></div>
        <?php endif; ?>

        <div class="meta collection-meta">
            <?php if ($collection->hasContributor()): ?>
            <div class="element">
                <h3><?php echo __('Contributors(s)'); ?></h3>
                <div class="element-text">
                    <p><?php echo metadata('collection', array('Dublin Core', 'Contributor'), array('all'=>true, 'delimiter'=>', ')); ?></p>
            <?php endif; ?>

<p class="view-items-link">
<?php echo link_to_items_browse(
                array('collection' => metadata('collection', 'id')),
                array('title' => __('View the items in %s', strip_tags(metadata('collection', array('Dublin Core', 'Title')))))
                ); ?></p>

            <?php fire_plugin_hook('public_collections_browse_each', array('view' => $this, 'collection' => $collection)); ?>

     </div><!-- end class="collection" -->
        <?php } ?>

    <?php endforeach; ?>

    <?php echo pagination_links(); ?>

    <?php else: ?>

    <p><?php echo __('There are no collections.'); ?></p>

    <?php endif; ?>

    <?php fire_plugin_hook('public_collections_browse', array('collections'=>$collections, 'view' => $this)); ?>

</div><!-- end primary -->

<?php echo foot(); ?>

I should also point out that I have added the 'Is Organisation' field to the elements table in the DB under Dublin Core, its a bit of a hack but it works and does what we need it to do.

The trouble is that the pagination is calculated in the query to the database before the records are sent to the page. So, as far as the pagination is concerned, it doesn't matter what records that are sent to the page are hidden.

Unfortunately, we don't have a way to search for a specific element value for collections.

If you are not using the "featured" option for other parts of your site organization and front page display, you could use featured as a substitute way to mark the collections that are organizations.

Then, you might not have to change that page at all. In Navigation you could turn off the default "Browse Collections" link, and add a new one with ?featured=1 appended to the same URL that Browse Collections uses. The same browse.php page would then be filtered to just the featured collections.

The same approach would also work on the collections' owner_id property, if you can have a single user whom you can make the owner of the appropriate collections.

We have managed to filter to show the 2 out of our 128 collections. However, the system is presenting us with 13 pages 12 of which are blank, the last page contains the 2 collections we wanted to show.
Is there any way we can manipulate the pagination list function to eliminate the excessive pages that are being output?