如何在附件页面上进行下一个和上一个附加图像导航?

时间:2014-07-17 作者:user45239

如何在附件页上进行下一个和上一个附件图像导航?

\'__(“上一幅图像”,“$text\\u domain”).“);?>”__(“下一幅图像”,“$text\\u domain”)。”);?>

工作很好:)

2 个回复
SO网友:Brad Dalton

使用previous_image_linknext_image_link 在图像中。php或附件。php文件。

<nav id="image-navigation" class="navigation image-navigation">
                <div class="nav-links">
                <?php previous_image_link( false, \'<div class="previous-image">\' . __( \'Previous Image\', \'$text_domain\' ) . \'</div>\' ); ?>
                <?php next_image_link( false, \'<div class="next-image">\' . __( \'Next Image\', \'$text_domain\' ) . \'</div>\' ); ?>
                </div><!-- .nav-links -->
            </nav><!-- #image-navigation -->
资料来源:Twenty Fourteen

SO网友:keesiemeijer

使用date query 按日期获取下一篇和上一篇(附件)文章。并从当前父帖子中排除所有子附件。

<?php
// use in template for single attachment display

// get all children ids (to exclude from the queries for next and previous post)
$args = array(
    \'post_status\'    => \'inherit\',
    \'post_type\'      => \'attachment\',
    \'post_mime_type\' => \'image\',
    \'fields\'         => \'ids\',
    \'post_parent\'    => $post->post_parent,
);

// get image attachments of parent (current post  will be included)
$children_ids = get_children( $args );

$args =  array(
    \'post_status\'    => \'inherit\',
    \'post_type\'      => \'attachment\',
    \'post_mime_type\' => \'image\',
    \'posts_per_page\' => 1,
    \'order\'          => \'DESC\',
    \'post__not_in\'   => $children_ids,
    \'date_query\'     => array(
        array(
            \'before\' => $post->post_date,
            \'column\' => \'post_date\',
        ),
    )
);

// get attachment with post date before current post date
$previous = get_posts( $args );

if ( isset( $previous[0]->ID ) ) {
    echo wp_get_attachment_link( $previous[0]->ID, \'thumbnail\', true );
}

// remove before
unset( $args[\'date_query\'][0][\'before\'] );

// add after and change order
$args[\'order\'] = \'ASC\';
$args[\'date_query\'][0][\'after\'] = $post->post_date;

// get attachment with post date after current post date
$next = get_posts( $args );

if ( isset( $next[0]->ID ) ) {
    echo wp_get_attachment_link(  $next[0]->ID, \'thumbnail\', true );
}
?>

结束

相关推荐

查询特定类别时,NEXT_POSTS_LINK不起作用

我想做的是显示“新闻”类别中的每一篇文章(在我的例子中,“新闻”类别的ID是13),每页5篇文章。页面上会显示分页链接,但当我单击“上一页”链接时,它只会显示类别中的前5篇文章。页面新闻的内容。php:<?php get_header(); ?> <h1 class=\"title\">Latest News</h1> <?php /*$args = array(\'cat\' => 13); $posts =