WordPress.org

Ready to get started?Download WordPress

Forums

WP Tiles
[resolved] Showing images attached to Custom Post Type post (7 posts)

  1. glovep
    Member
    Posted 9 months ago #

    Hello! First of all this is a fantastic plugin. Thank you for sharing it!

    My issue: While I have no troubles showing all Featured images of a Custom Post Type 'Portfolio' via this shortcode:

    [wp-tiles posts_query='numberposts=5&post_type=portfolio']

    I am now intending to show all images attached to it's post (of 'Portfolio'). I tried using this shortcode:

    [wp-tiles posts_query='numberposts=5&post_type=post']

    but it doesn't show the images. However, the title of the post is correct and also when clicking on it it links to the attached image of that post, it just doesn't show.

    Any thoughts?

    Thanks in advance!

    http://wordpress.org/plugins/wp-tiles/

  2. Mike
    Member
    Plugin Author

    Posted 9 months ago #

    Hi,

    To get the images attached to the current post, you need to query posts that are a child of the current post, and have the post type 'attachment'. You would have to include the parent post id manually though.. Your query would then look something like this:

    [wp-tiles posts_query='post_parent={POST_ID}&post_type=attachment&posts_per_page=-1&post_mime_type=image']

    Before version 0.5.6, it wouldn't grab the image for attachment posts though. I am uploading an update as we speak, so make sure you update to 0.5.6 when you try!

    Mike

  3. glovep
    Member
    Posted 9 months ago #

    Thanks Mike for your reply!

    Just upgraded to version 0.5.6 and used the code snippet from your example and added the ID:

    [wp-tiles posts_query='post_parent={1172}&post_type=attachment&posts_per_page=-1&post_mime_type=image']

    This seems to pull the attachments (from media library), but not the attachments from the particular post. Is there a better way without shortcode? I can also implement into the theme?

    Thank you!

  4. Mike
    Member
    Plugin Author

    Posted 9 months ago #

    Hi Glovep, I was unclear, sorry: change post_parent={1172} to post_parent=1172 and you should be sorted!

    Also in the theme you can implement it by calling the_wp_tiles with the above arguments. Like this:

    the_wp_tiles( array(
        posts_query => array(
            'post_parent'    => get_the_ID(),
            'post_type'      => 'attachment',
            'posts_per_page' => -1
            'post_mime_type' => 'image'
        )
    ) );

    (Untested.. so you'll want to double check that!)

    Cheers,
    Mike

  5. glovep
    Member
    Posted 9 months ago #

    Thanks Mike, this did the trick! I will try to integrate it into the theme and report back my results later. Thanks again!

  6. glovep
    Member
    Posted 8 months ago #

    Follow up: Integrating this straight into the theme with your code above works!

    My question would be, how can you define, say the template via this method? Or all the other settings that you can set via the shortcode?

    Maybe one can create some custom fields and read these fields in to add flexibility.

  7. Mike
    Member
    Plugin Author

    Posted 8 months ago #

    Hi Glovep. Good idea to load settings from custom fields. That kind of flexibility is exactly want I want to add when I go for the big 1.0 overhaul! (One day..)

    Now, you can pass all settings in the $args array. Have a look at the wp-tiles-defaults.php (hehe) to see what's possible.

    You can actually use custom fields in your own template, by passing the custom field as a param in this array. Something like this should work:

    // Get the value for 'show_selector' from meta field
    $show_selector = get_post_meta( get_the_ID(), 'show_selector', true );
    
    if ( !in_array( $show_selector, array( 'true', 'false' ) )
        $show_selector = 'true'; // Set Default
    
    // Do the tiles
    the_wp_tiles( array(
        posts_query => array(
            'post_parent'    => get_the_ID(),
            'post_type'      => 'attachment',
            'posts_per_page' => -1
            'post_mime_type' => 'image'
        ),
        'templates' => array(
            // Pass $show_selector to WP Tiles
            'show_selector' => $show_selector
        )
    ) );

    Mike

Reply

You must log in to post.

About this Plugin

About this Topic