• Resolved ferda2

    (@ferda2)


    How do I display a list of uploaded files on a post including links and a custom caption? Thank you.

    My field is documents (multiupload) – {@documments}

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Paul Clark

    (@pdclark)

    The below shortcode, [documents], when installed as a plugin, will display images with links and captions from the Description field for the current page:

    <?php
    /**
     * Plugin Name: Documents Shortcode
     * Description: Display images with links and captions from the <code>documents</code> field.
     * Author: ??δ???
     * Author URI: https://pd.cm/
     */
    
    add_action(
    	'plugins_loaded',
    	function(){
    		add_shortcode(
    			'documents',
    			function( $atts ) {
    				ob_start();
    
    				$document_ids = get_post_meta( get_the_ID(), 'documents', false );
    
    				foreach( $document_ids as $document_id ) {
    					printf(
    						'<figure>
    							<a href="%s">
    								<img src="%s" alt="%s" />
    								<figcaption>%s</figcaption>
    							</a>
    						</figure>',
    						wp_get_attachment_image_src( $document_id, 'full' )[0],
    						wp_get_attachment_image_src( $document_id, 'thumbnail' )[0],
    						esc_attr( get_post( $document_id )->post_content ),
    						esc_html( get_post( $document_id )->post_content )
    					);
    
    				}
    
    				return ob_get_clean();
    			}
    		);
    	}
    );
    Plugin Author Jory Hogeveen

    (@keraweb)

    Closing topic due to inactivity.
    Feel free to reach out if you still need help!

    Cheers, Jory

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Displaying a list of files for a post (multiupload)’ is closed to new replies.