【发布时间】:2010-04-23 17:58:44
【问题描述】:
我创建了一个自定义页面,并将其设置为我的主页,在此自定义页面中,我从特定类别中提取最新帖子,我还创建了一种分页形式,点击时将采用用户到 single.php。我对 single.php 的意图是有两个自定义循环。
自定义循环一 我希望 single.php 区分它来自主页,并循环浏览所有标记为与主页上相同类别的帖子。
其中一些帖子必须使用多个类别进行标记,因此循环必须知道忽略其他类别并只关注相关类别。这有意义吗?
自定义循环二 如果用户还没有从主页到达,single.php 将照常运行,即,如果用户来自 index.php(博客),他们将被带到第二个循环(博客文章)
但是我似乎无法区分这两个循环,我可能过于复杂了,因为我有一个循环将所有内容包装在一起,然后我有一个循环用于我的自定义分页。
这是下面的代码,向您展示我在说什么
custompage.php(设置为主页) - 这很好用,但我会发布它以防万一有人能够整理它
<?php query_posts('cat=1'); ?>
<?php
$myPosts = new WP_Query();
$myPosts->query('showposts=1');
if (have_posts()) :
while ($myPosts->have_posts()) : $myPosts->the_post();
?>
<script type="text/javascript">$.backstretch("<?php $key="image"; echo get_post_meta($post->ID, $key, true);?>");</script>
<div id="post-<?php the_ID(); ?>" class="info">
<h2><?php the_title(); ?></h2>
<ul class="nav">
<?php query_posts('posts_per_page=1&offset=1'); the_post(); ?>
<li class="prev"><a href="<?php the_permalink() ?>">Previous</a></li>
<?php wp_reset_query(); ?>
<li class="next"></li>
</ul>
</div>
<!-- end .info -->
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
single.php - 目前已损坏
<?php if( in_category('1') ) { ?>
<!-- start -->
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" class="info">
<script type="text/javascript">$.backstretch("<?php $key="image"; echo get_post_meta($post->ID, $key, true);?>");</script>
<h2><?php the_title(); ?></h2>
<ul class="nav">
<li class="prev"><?php previous_post_link('%link', ' ', 'true', '1') ?></li>
<li class="next"><?php next_post_link('%link', ' ', 'true', '1'); ?></li>
<!--li class="prev"><?php //previous_post_link('%link', '%title;', 'true', '1') ?></li>
<li class="next"><?php //next_post_link('%link', '%title;', 'true', '1'); ?></li-->
</ul>
</div>
<!-- end .info -->
<?php endwhile; else: ?>
<?php endif; ?>
<!-- end -->
<?php }else{ ?>
<div id="content" class="widecolumn" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_content('<p class="serif">Read the rest of this entry »</p>'); ?>
</div>
</div>
<?php comments_template(); ?>
<?php endwhile; else: ?>
<p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>
</div>
<?php } ?>
我似乎遇到的问题是,当帖子被标记为两个类别时,wordpress 似乎无法区分这两个类别,而是继续下一个类别,它打破了默认为第二个循环。
【问题讨论】:
-
我很想看到这个问题的答案。我也有过非常相似的挣扎。
-
嗨 Petrescu,欢迎来到 StackOverflow!编写问题时,无需在标题中重复标签(如 [wordpress])——最好放在“标签”字段中。这样问题就更容易阅读,而且如果阅读起来容易,则更有可能得到答案。
-
感谢您修复我的帖子标题 Max。
-
我遇到了类似的问题并想出了这个:stackoverflow.com/questions/13946468/…
标签: wordpress pagination categories