I'm having a hard time displaying the attachments in my post. Here is my instance declaration:
function projects_attachments( $attachments )
{
$fields = array(
array(
'name' => 'title', // unique field name
'type' => 'text', // registered field type
'label' => __( 'Title', 'attachments' ), // label to display
'default' => 'title', // default value upon selection
),
array(
'name' => 'type', // unique field name
'type' => 'select', // registered field type
'label' => __( 'Type', 'attachments' ), // label to display
'meta' => array( // field-specific meta as defined by field class
'allow_null' => false, // allow null value? (adds 'empty' <option>)
'multiple' => false, // multiple <select>?
'options' => array( // the <option>s to use
'1' => 'Screenshot',
'2' => 'Flash Banner',
)
),
),
array(
'name' => 'swf', // unique field name
'type' => 'text', // registered field type
'label' => __( 'SWF URL', 'attachments' ), // label to display
'default' => '', // default value upon selection
),
);
$args = array(
// title of the meta box (string)
'label' => 'Project Attachments',
// all post types to utilize (string|array)
'post_type' => array( 'projects' ),
// meta box position (string) (normal, side or advanced)
'position' => 'normal',
// meta box priority (string) (high, default, low, core)
'priority' => 'default',
// allowed file type(s) (array) (image|video|text|audio|application)
'filetype' => null, // no filetype limit
// include a note within the meta box (string)
'note' => 'Attach all project related files here.',
// by default new Attachments will be appended to the list
// but you can have then prepend if you set this to false
'append' => true,
// text for 'Attach' button in meta box (string)
'button_text' => __( 'Attach Files', 'attachments' ),
// text for modal 'Attach' button (string)
'modal_text' => __( 'Attach', 'attachments' ),
// which tab should be the default in the modal (string) (browse|upload)
'router' => 'browse',
// fields array
'fields' => $fields,
);
$attachments->register( 'projects_attachments', $args ); // unique instance name
}
add_action( 'attachments_register', 'projects_attachments' );
<?php $attachments = new Attachments( 'projects_attachments' );
if($attachments->exist()) :
?>
<div id="project-attachments">
<ul class="clearfix">
<?php
while( $attachment = $attachments->get() ) {
switch($attachment->field( 'type' )) {
case "1":
?>
<li><a href="<?php echo $attachment->src( 'full' ); ?>" rel="thumbs"><img src="<?php echo $attachment->image( 'thumbnail' ); ?>" alt="<?php echo $attachment->field( 'title' ); ?>" /></a></li>
<?php
break;
case "2":
?>
<li><a href="<?php echo $attachment->src( 'full' ); ?>" rel="thumbs"><img src="<?php echo $attachment->image( 'thumbnail' ); ?>" alt="<?php echo $attachment->field( 'title' ); ?>" /></a></li>
<?php
break;
}
} ?>
</ul>
</div>
<?php endif; ?>
Do you have any idea why it'd error out when trying to get $attachment->src( 'full' )? Also, when I print_r($attachment) it only shows the attachment ID, fields, and post ID. So for some reason it seems the object isn't being populated with everything as needed.