Getting URLs through PHP functions without HTML tags

I'm trying to create a series of image thumbnails that work as clickable links to different collections, with the name of the collection appearing over the photo on hover.

I have all the HTML markup with PHP set up the way I need, but I can't figure out how to pull in the URLs I need without being wrapped in all the HTML tags and formatting. I've tried strip_formatting and html_escape and $encode=false as a param but no combination of these seems to do what I want.

Here's what I've got:

<ul class="architect-collections">
  <?php $persons = get_records('Item', array( 'type' => 'Person' )); ?>
  <?php set_loop_records('Item', $persons); ?>
  <?php if(has_loop_records('Item')): ?>
    <?php foreach(loop('Items') as $person): ?>
  <?php $personcollection = get_collection_for_item($person); ?>
  <?php $personcollectionlink = link_to($personcollection); ?>
  <?php $personimage = record_image('Item', 'square_thumbnail'); ?>
  <?php $personimagelink = link_to($personimage); ?>

 	<?php $persontitle = metadata($personcollection, array('Dublin Core', 'Title')); ?>
  <li>
  <a href="<?php echo $personcollectionlink; ?>"><img title="<?php echo $persontitle; ?>" src="<?php echo $personimagelink; ?>">
  <span class="architect-title"><span><?php echo $persontitle; ?></span></span>
  </a>
  </li>
  <?php endforeach; ?>
   <?php endif; ?>
  </ul>

And just to clarify, this is what the PHP needs to spit out:

<ul class="architect-collections">
  <li>
  <a href="/Ms1987-061"><img title= "The Hilde Weström Architectural Collection, 1952-2000 (Ms1987-061)" src="http://192.168.15.11/files/square_thumbnails/Ms1987-061/Westrom_B_WPortrait/Westrom_B_WPortrait.jpg">
  <span class="architect-title"><span>The Hilde Weström Architectural Collection, 1952-2000 (Ms1987-061)</span></span>
  </a>
  </li>
  </ul>

I think your problem is that you're using the link_to function. link_to gets you the HTML for the whole link, with the a tag and everything.

If you just want a URL, not a link, you should use the record_url function instead.

So when I tried it with record_url I got an error:

variable has not been set to this view

Omeka_View_Helper_GetCurrentRecord->getCurrentRecord('<img src="http:...')...

I think the issue is that the record I'm trying to get is not set as the current record, which I guess is what record_url needs. How do I work around this?

You've got another function you shouldn't be using there, record_image. Just like link_to, that returns a full image tag with all the HTML, and you're building the tag manually and just want the URL.

What you want inside the loops should look more like this:

<?php
$personcollection = get_collection_for_item($person);
$personcollectionurl = record_url($personcollection);
$personimageurl = metadata($person, 'square_thumbnail_uri');
$persontitle = metadata($personcollection, array('Dublin Core', 'Title'));
?>

  <li>
  <a href="<?php echo $personcollectionurl; ?>"><img title="<?php echo $persontitle; ?>" src="<?php echo $personimageurl; ?>">
  <span class="architect-title"><span><?php echo $persontitle; ?></span></span>
  </a>
  </li>

After copying that code I got this error:
'square_thumbnail_uri' is an invalid special value.

But then I realized I needed to use that on the item's file, not the item itself. So I added a loop for the item's files and called the metadata function on the file.

<ul class="architect-collections">
  <?php $persons = get_records('Item', array( 'type' => 'Person' )); ?>
  <?php set_loop_records('Item', $persons); ?>
  <?php if(has_loop_records('Item')): ?>
    <?php foreach(loop('Items') as $person): ?>
   <?php $personcollection = get_collection_for_item($person); ?>
	<?php $personcollectionurl = record_url($personcollection); ?>
	<?php foreach (loop('files', $person->Files) as $index => $file): ?>
	<?php $personimageurl = metadata($file, 'square_thumbnail_uri'); ?>
	<?php $persontitle = metadata($personcollection, array('Dublin Core', 'Title'));?>
  <li>
  <a href="<?php echo $personcollectionurl; ?>"><img title="<?php echo $persontitle; ?>" src="<?php echo $personimageurl; ?>">
  <span class="architect-title"><span><?php echo $persontitle; ?></span></span>
  </a>
  </li>
  <?php endforeach; ?>
   <?php endforeach; ?>
   <?php endif; ?>
  </ul>

Now it works like a charm, thanks! I didn't realize you could pull file URIs with the metadata function, very cool!