WordPress.org

Ready to get started?Download WordPress

Forums

Custom Content Type Manager
[resolved] help about thumbnail (8 posts)

  1. thebuded
    Member
    Posted 2 years ago #

    Hi, I'm new to php so I followed your Overview video and on a movie page it successfully returned a lists of actors. but I also want to have the actors thumbnail to appear on the page, is this doable?

    Also on actors' page, I want to return a list of movies with thumbnail the actor acted in (this part is automatic without having me put in movies custom fields in the actor page.)

    Thank You.

    http://wordpress.org/extend/plugins/custom-content-type-manager/

  2. fireproofsocks
    Member
    Plugin Author

    Posted 2 years ago #

    Yes, it's possible, it just requires a bit more footwork to get the thumbnail. You can use the wp_get_attachment_image_src() or the wp_get_attachment_image() functions to retrieve an image given its ID, or try get_the_post_thumbnail(). If you are getting a list of actors, the thumbnail ID is stored inside a hidden field named "_thumbnail_id" -- that ID is what you want to pass to the WP functions. If you've stored the thumbnail as a custom field and NOT as the default WP "featured-image", then you'd use the custom field name to retrieve the ID.

    Re retrieving a list of movies featuring a given value, see the http://code.google.com/p/wordpress-custom-content-type-manager/wiki/TemplateFunctions page, specifically this function:
    http://code.google.com/p/wordpress-custom-content-type-manager/wiki/get_posts_sharing_custom_field_value

  3. thebuded
    Member
    Posted 2 years ago #

    Hi, Thank you, but it would be awesome if you could provide some working sample code. no worries if you're busy.

    Thank You.

  4. fireproofsocks
    Member
    Plugin Author

    Posted 2 years ago #

    Ha. I'm *always* busy. Check the FAQ, some sample code is there: http://code.google.com/p/wordpress-custom-content-type-manager/wiki/FAQ

  5. thebuded
    Member
    Posted 2 years ago #

    Ok I got it working.

    Thanks again for this great plugin!

  6. fireproofsocks
    Member
    Plugin Author

    Posted 2 years ago #

    Great! If you'd like to share your code, I'll post it on the Wiki for the benefit of others.

  7. thebuded
    Member
    Posted 2 years ago #

    Hi sure

    <?php
    $actor_thumb = get_custom_field('Actors:to_array', 'get_post');
    foreach ($actor_thumb as $at) {
    $thumbpermalink = get_permalink( $at['ID'] );
    $thumb = wp_get_attachment_image_src($at['_thumbnail_id']);
    ?>
    <a href="<?php echo $thumbpermalink ?>" title="<?php echo $at['post_title']; ?>" >
    <img src="<?php echo $thumb[0]; ?>" width="100" height="150">
    </a>
    <?php
    }
    ?>

    I only need the first part of my problem, second part I will use another plugin called "List category posts", it have some options best suits my needs.

  8. paulie22
    Member
    Posted 1 year ago #

    how to access a specific image sizing for an image field in CCTM:

    add to functions:

    add_image_size( 'contenttype-thumb', 216, 9999 );  // 216 is the width, set to whatever, 9999 is ignored (or swap to set height)
    add_theme_support( 'post-thumbnails', array( 'contenttype' ) );

    add to template page within loop:

    <?php
    global $post;
    $fieldname = 'large_poster';  //the image field name
    $image_id = get_post_meta($post->ID, $fieldname, true);
    $images = wp_get_attachment_image_src( $image_id, 'contenttype-thumb', true); 
    
    echo $images[0];
    ?>

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic