【问题标题】:Why does my second WP Custom post-type pagination not work?为什么我的第二个 WP Custom 后置分页不起作用?
【发布时间】:2013-09-17 17:23:54
【问题描述】:

有人提出了类似的问题,但似乎没有一个适用于我的情况。 我在 WP 网站中内置了两种自定义帖子类型。我创建了 single-first_one.php 来捕获每个第一个帖子类型。它运行良好,我添加的分页也有效。

第二个帖子类型,我创建了 single-second_one.php,在这个“单一”页面上,我显示了当前帖子,以及最近的 6 个帖子。除了我的分页链接(在 single-second_one.php 中)之外,一切都按原样显示。该代码几乎与第一个“单一”模板的代码相同,所以我不明白为什么它不起作用。有什么帮助吗?

<?php get_header(); ?>
<h1>Events</h1>
<section id=featured_post>

    <?php $paged = (get_query_var('paged') && get_query_var('paged') > 1) ? get_query_var('paged') : 1; ?>

        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

            <h5 class=previous><?php previous_post_link('%link'); ?></h5>
            <h5 class=next><?php next_post_link('%link'); ?></h5>

            <article class="post-<?php the_ID(); ?>">

                <div>
                    <?php if ( has_post_thumbnail()) : ?>
                        <?php the_post_thumbnail(); ?>
                    <?php endif; ?>
                </div>

                <h2><?php the_title(); ?></h2>
                <h3><?php the_time('l F j'); ?></h3>

                <?php the_content(); ?>

            </article>

        <?php endwhile; ?>
        <?php else: ?>
        <?php endif; ?> 
        <?php wp_reset_query(); ?>

</section>  
<h1>Upcoming Events</h1>
<section id=other_posts>

    <?php
        $args = array('post_type' => 'event', 'showposts' => 6, 'order' => 'ASC', 'post_status' => 'future');
        $loop = new WP_Query($args);

        if ( have_posts() ) : while ( $loop->have_posts() ) : $loop->the_post();?>

            <article class="post-<?php the_ID(); ?>">

                <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
                <h3><?php the_time('l F j'); ?></h3>
                <?php html5wp_excerpt('events_page_listing'); ?>

            </article>

    <?php  endwhile; else: ?>
    <?php endif; ?>         

</section>

我已经转到选项 -> 固定链接,缓存了所有内容,取出了调用最近六个帖子的后半部分,完全取出了 single-first_one.php,但没有任何效果。第二个单页分页的 's 是空的。

编辑

我尝试在 endwhile 之后、endwhile 和 else 之间移动下一个/上一个调用,等等。没有任何效果。这太奇怪了,因为在另一个 single.php 页面上,一切都以完全相同的方式设置,并且完美地显示了下一个/上一个帖子链接。

编辑

我添加了分页参数,但它仍然不起作用。

【问题讨论】:

  • 您使用过任何“类别”分类法吗?这些函数仅适用于“类别”分类。
  • 我没有任何分页参数..
  • @Obmerk 分页就在第一节打开之后 - 和以前一样...
  • 我的意思是我在查询中看不到 arguments 。看我的回答...

标签: wordpress pagination custom-post-type


【解决方案1】:

代码中没有任何分页参数..

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
  'posts_per_page' => 3,
  'paged' => $paged
);

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

query_posts('posts_per_page=3&paged=' . $paged);

或者类似的东西

$paged = (get_query_var('paged') && get_query_var('paged') > 1) ? get_query_var('paged') : 1;

【讨论】:

  • 我在上面添加了该代码(可能在错误的位置?),但它仍然无法正常工作。只是出于好奇,即使它是一个“single.php”文件,也不假设分页?再次重申一下,我在同一文件上使用的另一个单独的帖子文件,其代码与上面完全相同,正在按预期显示分页...
  • 但是您仍然没有在查询中添加arguments --
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-18
相关资源
最近更新 更多