简体   繁体   English

WordPress画廊的最新帖子

[英]Recent posts from wordpress gallery

I want to display recent images from wordpress gallery in the format like: 我想以以下格式显示来自wordpress画廊的最新图像:

<div class="portfolio-item">
            <div class="portfolio-overlay">
                <a href="HERE LINK ON IMAGE" data-lightbox="image-1" data-title="My caption"><img src="img/zoom.png" width="58" height="58" alt="" title=""></a>
            </div><!-- .portfolio-overlay-->
            <img class="pi-img" src="HERE LINK ON IMAGE" alt="" title="">
        </div><!-- .portfolio-item-->

How i should build my loop? 我应该如何建立循环? Thank You 谢谢

If you sort the query results 如果对查询结果进行排序

"SELECT * FROM gallery ORDER BY date ASC LIMIT ?"
// where ? is the number of rows you want to return

you can just do a simple foreach loop: 您可以执行一个简单的foreach循环:

foreach ($galleryPic as &$pic) {
//your code
}

First of all you should use thumbs for posts ( read more about post's thumbs ). 首先,您应该在帖子上使用大拇指( 更多有关帖子的大拇指的信息 )。 Than in your category template use this loop: 比在您的类别模板中使用以下循环:

    <?php if ( have_posts() ) : ?>
    <?php while ( have_posts() ) : the_post(); ?>
        <article class="post">
            <header>
                <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
                <span class="date"><time datetime="<?php the_time('Y-m-d'); ?>"><?php the_time('j F Y'); ?> <?php _e('в');?> <?php the_time('G:i'); ?></time></span>
                <span class="author"><?php _e( 'Author:', 'nikita-sp' ); ?> <?php the_author(); ?></span>
                <span class="category"><?php _e( 'in category', 'nikita-sp' ); ?> <?php the_category(', '); ?></span>
                <span class="comments"><?php comments_popup_link( __( '0 comments', 'nikita-sp' ), __( '1 comment', 'nikita-sp' ), __( '% comments', 'nikita-sp' )); ?></span>
                <?php edit_post_link( "Edit", '<span class="edit">', '</span>'); ?>
            </header>
            <?php the_content('read more...'); ?>
        </article>
    <?php endwhile; ?>
    <?php wp_pagenavi(); ?>
<?php else : ?>
        <article>
            <h2><?php printf( __( 'SEARCH RESULT for: %s' ), '<span>' . esc_html( get_search_query() ) . '</span>' ); ?></h2>
            <p class="center"><?php _e( 'Sorry, nothing was found', 'nikita_sp' ); ?></p>
            <?php get_search_form(); ?>
        </article>
<?php endif; ?>

Also use thumb output where y want. 也可以在需要的地方使用拇指输出。

                <?php if ( has_post_thumbnail()) : ?>
                    <?php the_post_thumbnail(); ?>
            <?php endif; ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM