Support » Plugin: Pods - Custom Content Types and Fields » Display uploaded files as list in template

  • Resolved Charl Beetge

    (@beetgemedia)


    Hi.

    I’m trying to show a list of my uploaded files in a PODS template per post, thus a single post per page with only that posts uploaded files in a list. It’s currently showing a list of all uploaded files per post, thus the current post as well as all the uploaded files for other posts. This is the code I’m using –

    <ul>
      [each attached_files]
    	<li><a href="{@attached_files._src}" target="_blank" rel="noopener">{@title}</a></li>
      [/each]
    </ul>

    I’m using this shortcode in my page template to display the list –
    [pods name="pigeon" limit="-1" template="Attached Files"]

    1) How do amend the code to only show the list of uploaded files for the post I’m in?
    2) Is it possible to show the file title and not the post title?

    Thank you

    Charl

    • This topic was modified 4 months, 1 week ago by Charl Beetge.
    • This topic was modified 4 months, 1 week ago by Charl Beetge.
    • This topic was modified 4 months, 1 week ago by Charl Beetge.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Paul Clark

    (@pdclark)

    1. [pods name="pigeon" use_current="1" template="Attached Files" ]
    2. In testing, {@title} as you have it showed the file title.

    See https://docs.pods.io/displaying-pods/pods-shortcode/

    Thread Starter Charl Beetge

    (@beetgemedia)

    Hi Paul

    Thank you kindly for the help 🙂

    I have 2 uploaded files per post, one jpg and another pdf, in no particular order. After updating the code to what you suggested, I now see 2 links per post which is great; but the first link is a loop back to the same post in a new tab, the second link is correct and opens the jpg/pdf in a new tab.

    What do you suggest I change and what could be the cause of the first listed link not linking to the jpg/pdf?

    Kind regards

    Charl

    Plugin Support Paul Clark

    (@pdclark)

    Hi Charl — unknown why it’s showing the Post Title instead of file title — it’s showing two file titles here.

    This code, which sets up the shortcode [pigeon_attached_files], should work:

    <?php
    
    add_shortcode(
    	'pigeon_attached_files',
    	function() {
    		ob_start();
    
    		$attached_files = get_post_meta( get_the_ID(), 'attached_files' );
    
    		echo '<ul>';
    		foreach ( $attached_files as $file ) {
    			?>
    			<li>
    				<a href="<?php the_permalink( $file['ID'] ); ?>">
    					<?php echo esc_html( get_the_title( $file['ID'] ) ); ?>
    				</a>
    			</li>
    			<?php
    		}
    		echo '</ul>';
    
    		return ob_get_clean();
    	}
    );
    Thread Starter Charl Beetge

    (@beetgemedia)

    Hi Paul, again thank you for the help.

    Stupid question, what and where do I place the code to set up the shortcode which you sent? In the child theme function file or as a code module on the template page?

    Just to confirm this code is in the PODS settings as Template –

    <ul>
      [each attached_files]
    	<li><a href="{@attached_files._src}" target="_blank" rel="noopener">{@title}</a></li>
      [/each]
    </ul>

    I created a template in my theme to show each custom post type, this is the shortcode I use in the module where it should show the attached files –
    [pods name=”pigeon” use_current=”1″ template=”Attached Files” ]

    This is a URL (https://fly.bmtest.co.za/pigeons/za-svpv-1110-16/) to one of the posts, which you will see on the right of the page at the bottom is a heading saying “PEDIGREE & OTHER DOCUMENTS”, there is a list of the files attached to this post. In this post, there should be 3 files for this particular bird, 1x pdf and 2x jpg’s. The list is showing but the first URL opens the same post in a new tab and does not link to the file, the second and 3 links open the same file.

    Thank you

    Charl

    Plugin Support Paul Clark

    (@pdclark)

    The shortcode code can be placed in your theme’s functions.php or installed as a plugin by adding the header:

    
    <?php
    /**
     * Plugin Name: XXX
     */
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.