我已经创建了一个自定义页面,并将其设置为我的主页,在此自定义页面内我从特定类别中提取最新帖子,还创建了一种分页形式,当点击该分页时会将用户到single.php。我对single.php的意图是有两个自定义循环。如何通过Wordpress中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 } ?>
的proble我似乎碰到的是,当一个帖子被标记为两个类别时,wordpress似乎无法区分这两个类别,而是继续进入下一个类别,并且默认为第二个类别循环。
我很乐意看到这个问题的答案。我有过类似的斗争。 – 2010-04-23 18:03:55
嗨,Petrescu,欢迎来到StackOverflow!在撰写问题时,不需要在标题中重复标签(如[wordpress]) - 最好放置在“标签”字段中。这样,问题更容易阅读,并且如果它很容易阅读,则更有可能得到答案。 – MaxVT 2010-04-23 18:15:33
感谢您修复我的文章标题最大。 – petrescu 2010-04-23 18:24:53