【问题标题】:Recent posts from wordpress gallery来自 wordpress 画廊的最新帖子
【发布时间】:2014-05-06 00:35:54
【问题描述】:

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

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

【问题讨论】:

    标签: php html wordpress


    【解决方案1】:

    如果对查询结果进行排序

    "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
    }
    

    【讨论】:

      【解决方案2】:

      首先,您应该在帖子中使用拇指 (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; ?>
      

      还可以在需要的地方使用拇指输出。

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

      【讨论】:

        猜你喜欢
        • 2017-05-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-17
        • 1970-01-01
        • 1970-01-01
        • 2018-12-22
        相关资源
        最近更新 更多