Wordpress 网格/列表视图 [英] Wordpress grid/list view
问题描述
有谁知道在 wordpress 中实现列表/网格可切换视图的最佳方法是什么?更清楚地说:默认视图显示列表中的帖子,我希望可以选择在网格中显示它们.到目前为止,我已经创建了一个仅显示缩略图的循环,并将其包含在另一个模板中.但我不知道如何链接到该视图.我最好使用存档视图吗?
Does anyone know what the best way to implement a list/grid togglable view in wordpress would be? To be more clear: the default view shows the posts in a list, I would like to have the option to show them in a grid. I have so far created a loop which shows only the thumbnails, and included it in another template. But I don't know how I would link to that view. Would I best off using an archive view?
谢谢.
推荐答案
最简单的解决方案之一是创建一个 页面模板 包含网格视图并在列表视图中添加到此页面的链接.非常简单,但正是您所需要的.
One of the easiest solutions is to create a page template containing a grid view and add a link to this page in the list view. Very simple but just what you need.
我在分页方面遇到了同样的问题.WordPress 内置了posts_nav_link 函数,如果需要,它会自动打印上一页和下一页的链接.问题是此函数仅适用于 WP_Query 的 $wp_query 实例(默认情况下使用此实例,例如获取页面内容或主页中的最新帖子).那么适合您的解决方案:
I had the same issue with pagination. WordPress has built in function posts_nav_link that automatically prints links to previous and next pages if needed. The problem is that this function works only with $wp_query instance of WP_Query (this instance is used by default, for example to get page's content or the latest posts in home). So the solution for you:
<?php
$temp=$wp_query;
$wp_query=null;
$wp_query = new WP_Query('showposts=4');
while(have_posts() ) : the_post(); ?>
<?php the_post_thumbnail( array(160,160) );?>
<h2><?php the_title(); ?></h2>
<?php endwhile;
posts_nav_link();
$wp_query = $temp; ?>
我认为这很明显,不需要解释:) 应该有效
I think that's quite obvious and there is no need of explanation :) should be working
这篇关于Wordpress 网格/列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!