0

I'm trying to build a picture gallery with custom post type in my theme and I think i figure it out almost everything but the call in the template, I already have the custom post type in the functions.php, I have a Page with a custom call to the post type and it’s working (the post are showing in the page with the template) what I cannot figure it out it’s the call for the href that should go to open the image bigger probably with some modal like lightbox or something like that.

I have to mention that I’m trying to use feature image and already have created some image sizes for it in the functions.php, I’m going to paste the code for you to understand… Thank you in advance

Custom post type template

<?php
/*      
    Template Name: test Post Type Gallery   
*/
get_header(); 
?>
<div id="container">
    <div id="content" role="main">

        <?php $loop = new WP_Query( array( 'post_type' => 'bird', 'posts_per_page' => 10 ) ); ?>
        <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

        <ul class="gallery-ul">
            <li class="the-picture"><?php the_title( '<h2 class="picture-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h2>' ); ?>
            <a href="-----?????????--------"> <?php the_post_thumbnail(array(200,200)); ?></a></li>
        </ul>

        <?php endwhile; ?>

    </div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Functions.php
This is for the Size of the Images

if ( function_exists( 'add_theme_support' ) ) { 
    add_theme_support( 'post-thumbnails' );
    set_post_thumbnail_size( 250, 250, true ); // Normal post thumbnails
    add_image_size( 'medium-picture-thumbnail', 400, 400 ); // Medium thumbnail size
    add_image_size( 'big-picture-thumbnail', 700, 700 ); // Big thumbnail size
}

2 Answers 2

2
                    <a rel="lightbox" href="<?php $image_id = get_post_thumbnail_id();
                $image_url = wp_get_attachment_image_src($image_id,'large', true);
                echo $image_url[0];  ?>">
                <?php the_post_thumbnail('thumbnail'); ?>
                </a>

Yeah the above (posted by @null) is correct on getting the url, here it is all put together. Including the rel=lightbox. I call to WP's large image size here personally for the lightbox image to be linked to.
the_post_thumbnail wp_get_attachment_image_src

5
  • Good timing, I had just gone through making this work on my theme! Commented Feb 23, 2011 at 14:30
  • @iceman725 - If Rev. Voodoo answered your question you should mark it as correct so that the question shows up as answered :) Commented Feb 23, 2011 at 14:31
  • +1 from me. Might i suggest adding a link to the codex pages for the two functions used as a quick reference.
    – t31os
    Commented Feb 23, 2011 at 16:14
  • sorry, how can I do that? mark it as answered?? I'm a newbie
    – user3422
    Commented Feb 23, 2011 at 16:14
  • You may not be able to mark the answer as correct yet, there's a minimum wait period before an answer can be selected(i can't recall what that is, i've only asked one question).
    – t31os
    Commented Feb 23, 2011 at 16:46
1

So by the sounds of it your having problems with the function the_post_thumbnail. Essentially you just need that to return a URL rather than the image. Give this a try:

$src = wp_get_attachment_image_src( get_post_thumbnail_id($loop->the_ID()), array( 800,600 ), false, '' );
echo $src[0];

Set the array(width,height) to your desired image size and echo $src[0] into your href="--------???????---------" attribute.

1
  • +1, for pointing out the two functions that solved the problem , from the start.
    – t31os
    Commented Feb 23, 2011 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.