Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Photo caption table for attachments to current post #17

Open
r-brown opened this issue Aug 30, 2015 · 3 comments
Open

Photo caption table for attachments to current post #17

r-brown opened this issue Aug 30, 2015 · 3 comments
Labels
enhancement hacktoberfest Hacktoberfest ready issue

Comments

@r-brown
Copy link
Member

r-brown commented Aug 30, 2015

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

@r-brown r-brown added the ready label Aug 30, 2015
@r-brown r-brown self-assigned this Aug 30, 2015
@r-brown r-brown removed the ready label Feb 26, 2016
@r-brown r-brown added the hacktoberfest Hacktoberfest ready issue label Oct 2, 2017
@Jaace
Copy link
Contributor

Jaace commented Oct 20, 2017

I can look into this!

@r-brown
Copy link
Member Author

r-brown commented Oct 20, 2017

Hi @Jaace - absolutely, thank you for your support!

@Jaace
Copy link
Contributor

Jaace commented Oct 21, 2017

About to push up a commit. A few notes - if the image isn't attached to anything, it won't show, so make sure it's actually attached to the post you expect.

Wherever the shortcode is included (widget or in the post_content), the post ID is used, so if it's in the sidebar, it will be relative to the page being viewed.

This brought to light an issue where if the image doesn't have any credit tracker meta saved, it doesn't show in the table at all, but the table could still show the headers. This is because the table only checks if the image exists, but not if the meta exists for the image. This could be another ticket as it's not directly related to this fix.

@r-brown r-brown removed their assignment Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement hacktoberfest Hacktoberfest ready issue
Development

No branches or pull requests

2 participants