来自wordpress画廊的最新帖子

时间:2014-05-05 14:54:19

标签: php html wordpress

我想以如下格式显示来自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-->

我应该如何构建循环? 谢谢

2 个答案:

答案 0 :(得分:0)

如果您对查询结果进行排序

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

你可以做一个简单的foreach循环:

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

答案 1 :(得分:0)

首先,你应该使用大拇指来发帖(read more about post's thumbs)。在您的类别模板中使用此循环:

    <?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; ?>

也可以在y想要的地方使用拇指输出。

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