简体   繁体   English

带有类别的Wordpress上的旧/先前帖子

[英]Older/Previous Posts on Wordpress with Categories

I'm having some major problems getting my older/newer posts working on Wordpress when only showing 1 category's posts on a page. 仅在页面上显示1个类别的帖子时,让我的旧/新帖子在Wordpress上工作时遇到一些重大问题。

It worked absolutely fine before I was defining a category, but now my client wants one category on one page, and another category on another. 在定义类别之前,它工作得非常好,但是现在我的客户想要在一个页面上一个类别,在另一个页面上另一个类别。

The code that I'm using is pasted below. 我正在使用的代码粘贴在下面。 If you'd like a temporary login, I can set you up.. this has been driving me crazy for the past 2 hours! 如果您想要临时登录,我可以设置您..在过去的2个小时里,这使我疯狂!

<?php $my_query = new WP_Query($querystring . 'cat=3&posts_per_page=8');
  while ($my_query->have_posts()) : $my_query->the_post();
  $do_not_duplicate = $post->ID; ?>

<?php /* Start the Loop */ ?>


                <?php get_template_part( 'content', get_post_format() ); ?>


        <div class="post"  id="post-<?php the_ID(); ?>">     
                    <h2 class="date"><?php the_time('F j, Y') ?></h2></div>

            <div class="entry-content">
                <?php the_content('Read the rest of this entry'); ?>
                <?php wp_link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?>

                                </div>

        <?php endwhile; ?>

Replace your code with this corrected version. 用此更正的版本替换您的代码。 You have to use query_posts to work with $querystring, not WP_Query (because it is not new, it is using the same one, complementing its querystring with other parameters): 您必须使用query_posts来处理$ querystring,而不是WP_Query(因为它不是新的,它使用的是相同的字符串,并使用其他参数来补充其querystring):

<?php query_posts($querystring . 'cat=-123&posts_per_page=8');
if ( have_posts() ) while ( have_posts() ) : the_post();
$do_not_duplicate = $post->ID; ?>

<?php /* Start the Loop */ ?>


            <?php get_template_part( 'content' ); ?>


    <div class="post"  id="post-<?php the_ID(); ?>">     
                <h2 class="date"><?php the_time('F j, Y') ?></h2></div>

        <div class="entry-content">
            <?php the_content('Read the rest of this entry'); ?>
            <?php wp_link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?>

                            </div>

    <?php endwhile; ?>

Thanks your your help. 谢谢您的帮助。 I've managed to get it working using the WP Posts Filter plugin. 我设法使用WP Posts Filter插件使其工作。 Not perfect, but a workaround which does what I need it to. 不是完美的,但是可以解决我需要的解决方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM