Skip to content

Photo caption table for attachments to current post #17

@r-brown

Description

@r-brown

How would I construct the shortcode so it displays the photo credit table for all photos attached to the current post? currently, i'm implementing the shortcode in a sidebar on all blog pages.

remove_shortcode( 'credit_tracker_table' );
    add_shortcode( 'credit_tracker_table', 'my_credit_tracker_table_shortcode' ) );

    function my_credit_tracker_table_shortcode( $atts ) {
        extract( shortcode_atts( array(
             'attachments' => false
        ), $atts ) );
        if ( $attachments ) {
            global $post;
            $attachments    = get_attached_media( 'image' );
            $attachment_ids = array();
            foreach ( $attachments as $attachment ) {
                $attachment_ids[] = $attachment->ID;
            } //$attachments as $attachment
            $attachment_ids = implode( ',', $attachment_ids );
            $atts[ 'id' ]   = $attachment_ids;

        } //$attachments
        return ( credit_tracker_table_shortcode( $atts ) );
    }

Source: https://wordpress.org/support/topic/photo-caption-table-for-attachments-to-current-post

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions