我有一个使用缩略图网格的wordpress网站(9个帖子,3个帖子宽,响应)每个帖子上的精选图片创建网格。
我控制网格的代码是
<?php
/**
* controls main grid images
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class('col-md-4 col-sm-4 pbox '); ?>>
<div class = "box-ovrly">
<h2 class="box-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<div class="box-meta"><?php the_category(', '); ?></div>
</div>
<?php
$thumb = get_post_thumbnail_id();
$img_url = wp_get_attachment_url( $thumb,'full' ); //get full URL to image (use "large" or "medium" if the images too big)
$image = aq_resize( $img_url, 750, 560, true ); //resize & crop the image
?>
<?php if($image) : ?>
<a href="<?php the_permalink(); ?>"> <img class="img-responsive" src="<?php echo $image ?>"/></a>
<?php endif; ?>
</article><!-- #post-## -->
它会创建一个网格,但它会以相反的顺序显示(9到1,而不是1到9)。这不是一个大问题,但我已经接下来了#39;和之前的&#39;没有与帖子协调的按钮。
实施例。在我的第一篇文章中,之前的&#39;按钮出现因为它认为它在第9个帖子等。
使用以下
创建后退/下一个菜单function web2feel_content_nav( $nav_id ) {
global $wp_query, $post;
// Don't print empty markup on single pages if there's nowhere to navigate.
if ( is_single() ) {
$previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
$next = get_adjacent_post( false, '', false );
if ( ! $next && ! $previous )
return;
}
// Don't print empty markup in archives if there's only one page.
if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) )
return;
$nav_class = ( is_single() ) ? 'post-navigation' : 'paging-navigation';
?>
<nav role="navigation" id="<?php echo esc_attr( $nav_id ); ?>" class="<?php echo $nav_class; ?> row">
<h1 class="screen-reader-text"><?php _e( 'Post navigation', 'web2feel' ); ?></h1>
<?php if ( is_single() ) : // navigation links for single posts ?>
<?php previous_post_link( '<div class="nav-previous col-xs-6">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'web2feel' ) . '</span> %title' ); ?>
<?php next_post_link( '<div class="nav-next col-xs-6">%link</div>', '%title <span class="meta-nav">' . _x( '→', 'Next post link', 'web2feel' ) . '</span>' ); ?>
<?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>
<?php if ( get_next_posts_link() ) : ?>
<div class="nav-previous col-md-6"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'web2feel' ) ); ?></div>
<?php endif; ?>
<?php if ( get_previous_posts_link() ) : ?>
<div class="nav-next col-md-6"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'web2feel' ) ); ?></div>
<?php endif; ?>
<?php endif; ?>
</nav><!-- #<?php echo esc_html( $nav_id ); ?> -->
<?php
}