WordPress.org

Ready to get started?Download WordPress

Forums

Attachments
[resolved] Custom Post Type Images not showing (6 posts)

  1. Blue Phoenix
    Member
    Posted 1 year ago #

    I've successfully set up the attachments plugin on a theme within a test environment which includes a 'portfolio' custom post type.

    The attachments appear within Admin correctly and can be attached to the portfolio post however these images do not appear within the front end, in fact none of the data appears.

    Using the exact same code within the standard post page, I tested this and it appears to work correctly displaying the images without problem.

    Is there something I'm doing incorrectly or may have missed in order to make this work within the portfolio posts of the site?

    http://wordpress.org/extend/plugins/attachments/

  2. Jonathan Christopher
    Member
    Plugin Author

    Posted 1 year ago #

    Did you edit your theme template file? Did you update the instance name to match the instance name you used when setting it up for your CPT? Can you paste some code samples for me to check out? Ideally the code you used to set up the instance (if you used a custom instance instead of the default) and the code you're using in your template file to try to get Attachments to show up on the front end.

  3. Blue Phoenix
    Member
    Posted 1 year ago #

    Functions.php has this

    function my_attachments( $attachments )
    {
    $args = array(
    
    // title of the meta box (string)
    'label' => 'My Attachments',
    
    // all post types to utilize (string|array)
    'post_type' => array( 'post', 'page', 'portfolio' ),
    
    // allowed file type(s) (array) (image|video|text|audio|application)
    'filetype' => image, // no filetype limit
    
    // include a note within the meta box (string)
    'note' => 'Attach files here!',
    
    // text for 'Attach' button in meta box (string)
    'button_text' => __( 'Attach Files', 'attachments' ),
    
    // text for modal 'Attach' button (string)
    'modal_text' => __( 'Attach', 'attachments' ),
    
    /**
    * Fields for the instance are stored in an array. Each field consists of
    * an array with three keys: name, type, label.
    *
    * name - (string) The field name used. No special characters.
    * type - (string) The registered field type.
    * Fields available: text, textarea
    * label - (string) The label displayed for the field.
    */
    
    'fields' => array(
    array(
    'name' => 'title', // unique field name
    'type' => 'text', // registered field type
    'label' => __( 'Title', 'attachments' ), // label to display
    ),
    array(
    'name' => 'caption', // unique field name
    'type' => 'textarea', // registered field type
    'label' => __( 'Caption', 'attachments' ), // label to display
    ),
    array(
    'name' => 'copyright', // unique field name
    'type' => 'text', // registered field type
    'label' => __( 'Copyright', 'attachments' ), // label to display
    ),
    ),
    
    );
    
    $attachments->register( 'my_attachments', $args ); // unique instance name
    }
    
    add_action( 'attachments_register', 'my_attachments' );

    With in the loop of single-portfolio.php the following is added

    <?php $attachments = new Attachments( 'attachments' ); /* pass the instance name */ ?>
    <?php if( $attachments->exist() ) : ?>
    
        <?php while( $attachments->get() ) : ?>
    		<img src="<?php echo $attachments->src( 'full' ); ?>"/>
    
        <?php endwhile; ?>
    
    <?php endif; ?>

    Let me know if anything else is required

    [Please post code or markup snippets between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

  4. Jonathan Christopher
    Member
    Plugin Author

    Posted 1 year ago #

    Please note that your functions.php is naming the instance my_attachments and your single-portfolio.php is using an instance name attachments.

  5. Blue Phoenix
    Member
    Posted 1 year ago #

    Now I feel a bit of a muppet for something so simple, but that's resolved the issue.

    Really appreciate your help

  6. Jonathan Christopher
    Member
    Plugin Author

    Posted 1 year ago #

    Glad it helped, you're definitely not the first person to have the issue. Unfortunately it's a bit of a catch-22 concerning the 'big picture' in the documentation. I do plan on revising and clarifying things a bit and making it easier to digest. Glad you're all set!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic