在图像附件中显示帖子摘录

时间:2012-09-10 作者:user20264

我想在下面的图片附件中显示这篇文章的摘录,这是我的代码

<?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="<?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="<?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 个回复
最合适的回答,由SO网友:ifdion 整理而成

首先参考此answer 作者@MikeSchinkel。您可以将函数放入函数中。php

接下来,只需添加echo robins_get_the_excerpt($post->post_parent); 图像附件下方。像这样:

<div class="caption">
    <?php echo robins_get_the_excerpt($post->post_parent) ?>
</div>
请注意,此代码未经测试。

结束

相关推荐

images within style sheet

我希望有人能在这方面帮助我,因为这已经开始让我抓狂了。我已经搜索了好几个小时,想找到一种在我的样式表中放置图像路径的方法,但一直没有找到。路径不能是绝对路径或“主题相关”路径。解决问题的唯一方法是在html文件中添加以下内容:<style type=\"text/css\"> #menu .menu-drop .menu-label { background: url(<?php echo get_template_directory_uri().