Show Post Excerpt in Image Attachement

I want to show excerpt from the post in the below image attachment, here’s my code

<?php
/**
 * Image Template
 *
 * Displays singular WordPress Media Library items.
 *
 * @package Thematic
 * @subpackage Templates
 *
 * @link http://codex.wordpress.org/Using_Image_and_File_Attachments Codex:Using Attachments
 */

    // calling the header.php
    get_header();

    // action hook for placing content above #container
    thematic_abovecontainer();
    ?>

    <div id="container">

        <?php
        // action hook for placing content above #content
        thematic_abovecontent();

        // filter for manipulating the element that wraps the content 
        echo apply_filters('thematic_open_id_content', '<div id="content">' . "\n\n");

        // start the loop
        while (have_posts()) : the_post();

            // action hook for placing content above #post
            thematic_abovepost();
            ?>

            <?php
            // creating the post header
            thematic_postheader();
            ?>
            <?php include 'share.php'; ?>

            <div class="entry-content">

                <div class="gallerytop">Posted In: <a href="https://wordpress.stackexchange.com/questions/64749/<?php echo get_permalink($post->post_parent); ?>" rev="attachment"><?php echo get_the_title($post->post_parent); ?></a></div>

                <div class="galleryentry">
                    <?php
                    $parent = $post->post_parent;
                    $attachments = array_values(get_children(array('post_parent' => $post->post_parent, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'DESC', 'orderby' => 'ID')));

                    foreach ($attachments as $k => $attachment)
                        if ($attachment->ID == $post->ID)
                            break;

                    $next = $k + 1;
                    $prev = $k - 1;
                    $next_link = "";
                    $prev_link = "";

                    if (isset($attachments[$next])) {
                        $next_exists = 1;
                        $next_link = "<a href="" . get_attachment_link($attachments[$next]->ID) . ""> Next Photo >></a>";
                        $img_link = "<a href="" . get_attachment_link($attachments[$next]->ID) . "">";
                    }

                    if (isset($attachments[$prev])) {
                        $prev_exists = 1;
                        $prev_link = "<a href="" . get_attachment_link($attachments[$prev]->ID) . ""> << Previous Photo</a>";
                        if (!$next_exists) {
                            $img_link = "<a href="" . get_attachment_link($attachments[$prev]->ID) . "">";
                        }
                    }

                    if (!$next_exists and !$prev_exists) {
                        $img_link = "<a href="" . get_attachment_link($attachments[$k]->ID) . "">";
                    }
                    ?>
                    <p class="attachment"><?php echo $img_link;
                echo wp_get_attachment_image($post->ID, 'full'); ?></a></p>
                    <div class="caption"><?php if (!empty($post->post_excerpt)) the_excerpt(); ?></div>

                    <div class="imgnavigation">
                        <div class="navleft"><?php echo $prev_link ?></div>
                        <div class="navright"><?php echo $next_link ?></div>
                    </div>
                    <br class="clear" />
                    <div class="gallery">
                        <div class="ig">
        <?php
        $post_parent = get_post($post->ID, ARRAY_A);
        $parent = $post_parent['post_parent'];

        $attachments = get_children("post_parent=$parent&post_type=attachment&post_mime_type=image&orderby=menu_order DESC, ID ASC");
        foreach ($attachments as $id => $attachment) :
            echo wp_get_attachment_link($id, 'thumbnail', true);
        endforeach;
        ?></div></div>




                    <div class="moreread"><a href="https://wordpress.stackexchange.com/questions/64749/<?php echo get_permalink($post->post_parent); ?>" rev="attachment">Read Full Gossip Here >></a></div>

                </div><!-- .entry-content -->

        <?php
        // creating the post footer
        thematic_postfooter();
        ?>

            </div><!-- #post -->

                <?php
                // action hook for placing contentbelow #post
                thematic_belowpost();

                // action hook for calling the comments_template
                thematic_comments_template();

            // end loop
            endwhile;
            ?>

    </div><!-- #content -->

        <?php
        // action hook for placing content below #content
        thematic_belowcontent();
        ?>      
    </div><!-- #container -->

    <?php
    // action hook for placing content below #container
    thematic_belowcontainer();

    // calling the standard sidebar 
    thematic_sidebar();

    // calling footer.php
    get_footer();
?>

1 Answer
1

First refer to this answer by @MikeSchinkel. You can put the function in functions.php

Next, just add echo robins_get_the_excerpt($post->post_parent); below the image attachment. Like this :

<div class="caption">
    <?php echo robins_get_the_excerpt($post->post_parent) ?>
</div>

Please note that this code is untested.

Leave a Comment