定义了特定 post_type 的帖子内的页面导航在 Wordpress 中不起作用

2024-04-30

http://lakers.sonikastudios.com/gallery/sample-gallery-post-1/ http://lakers.sonikastudios.com/gallery/sample-gallery-post-1/

该帖子有几个页面使用Wordpress 的快速标签。这篇文章也是一个自定义的 post_type.. 在主题模板的functions.php 中使用以下代码。

add_action( 'init', 'create_post_type' );
    function create_post_type() {
        register_post_type( 'gallery',
            array(
                'labels' => array(
                'name' => __( 'Galleries' ),
                'singular_name' => __( 'Gallery' )
            ),
            'public' => true,
            'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'custom-fields', 'comments')
            )
        );

通过这段代码,我成功地在管理部分中显示了自定义帖子类型。我在那里添加了一篇新文章,带有翻页器..

因此,使用 wp_link_pages() 函数,我使页面翻转功能正常工作。但它仅适用于类别下的常规帖子,不适用于定义为“图库”post_type 的帖子。例如这个页面http://lakers.sonikastudios.com/editorials/捕捉-the-buss-to-the-hall-of-fame/3/ http://lakers.sonikastudios.com/editorials/catching-the-buss-to-the-hall-of-fame/3/与帖子内的分页配合得很好。

我没有使用任何影响帖子显示方法或导航的插件,并且我没有弄乱 .htaccess 文件 - 无论 WordPress 写什么,都是我得到的。

任何帮助都会很棒......该网站几乎准备好了,我们遇到了这个瓶颈,这让我很沮丧!

我正在使用最新版本的 Wordpress,并开始使用 Whiteboard 主题(为 WP3 制作的新主题)进行开发。 ]

更新: gallery.php(通过页面模块分配以显示 post_type“画廊” - 我确认这是我加载画廊 post_type 帖子时加载的文件)

<?php
/*
Template Name: Gallery
*/
?>

<?php get_header();

$exclude = array();

?>
<div class="grid_11" id="mainbar">



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

    $exclude[]=get_the_ID();
    ?>
            <div id="post-<?php the_ID(); ?>" <?php post_class('grid_11 alpha omega'); ?>>
                <h2><a href="<? the_permalink(); ?>" title="<? the_title();?>"><? the_title();?></a></h2>
                <div class="social_media_balloons">
                <?
                if (function_exists('fbshare_manual')) echo fbshare_manual();
                ?>
                <?
                if (function_exists('tweetmeme')) echo tweetmeme();
                ?>
                </div>
                    <?
                    $author_gravatar = get_gravatar(get_the_author_meta('user_email'));
                    ?>
                    <img src="<? echo $author_gravatar;?>" class="alignleft" />
            <?
            echo posted_by_and_category();

            ?>

                    <div class="grid_11 alpha omega">

                        <?php the_content(); ?>
                        <div id="single_article_selectors">

                        <?php wp_link_pages('before=<div class="single_article_selector">&after=</div>'); ?>
                        <?php wp_link_pages('before=<div class="single_article_selector">&after=</div>&next_or_number=next'); ?>

                        </div>

                        <div class="grid_11 alpha omega" id="social_media_links">
                        <div class="grid_5 alpha">
                            <p><a href="http://www.twitter.com/LakersNation" target="_blank"><img src="/images/twittericon.jpg" alt="Twitter" width="32" height="32" class="alignleft">Follow Lakers Nation </a></p>
                            <p><a href="http://feeds.feedburner.com/LakersNation" target="_blank"><img src="/images/rssicon.jpg" alt="Twitter" width="32" height="32" class="alignleft">Subscribe to Lakers Nation</a></p>
                        </div>
                        <div class="grid_5 omega">
                            <p><a href="http://www.facebook.com/lakersnation" target="_blank"><img src="/images/fbicon.jpg" alt="Twitter" width="32" class="alignleft">Become a Fan on Facebook</a></p>
                            <p><a href="http://itunes.apple.com/us/app/app-of-l-nation/id349346678?mt=8" target="_blank"><img src="/images/iphoneicon.png" alt="Twitter" width="32" height="32" class="alignleft">Download our Free iPhone App</a></p>
                        </div>
                    </div>


                        <div class="shadow_divider"></div>
                    </div><!--#post-content-->

                    <!-- If a user fills out their bio info, it's included here -->
                    <div id="post-author" class="grid_11 alpha omega">
                        <h3>Written by <?php the_author_posts_link() ?></h3>
                        <div id="author-gravatar">
                            <!-- This avatar is the user's gravatar (http://gravatar.com) based on their administrative email address -->
                            <?php echo get_avatar( $curauth->user_email, $default = '<path_to_url>' ); ?>
                        </div><!--#author-gravatar -->
                        <div id="authorDescription">
                            <?php the_author_meta('description') ?> 
                            <div id="author-link">
                                <p>View all posts by: <?php the_author_posts_link() ?></p>

                            </div><!--#author-link-->
                        </div><!--#author-description -->
                    </div><!--#post-author-->

                </div><!-- #post-## -->

                <div class="grid_11 alpha omega next_prev_links">
                    <div class="grid_3 alpha">
                        <p>
                            <?php previous_post_link('%link', '&laquo; Previous post') ?>
                        </p>
                    </div><!--.older-->
                    <div class="grid_3 omega" style="float:right; text-align:right;">
                        <p>
                            <?php next_post_link('%link', 'Next Post &raquo;') ?>
                        </p>
                    </div><!--.older-->
                </div><!--.newer-older-->

                <?php comments_template( '', true ); ?>

    <?php endwhile; ?><!--end loop-->
</div><!--#content-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

single.php(默认情况下常规帖子显示模板..)

<?php get_header();

$dirpath = str_replace(get_bloginfo('url'), '',get_bloginfo('template_directory'));
?>
<div class="grid_11" id="mainbar">



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

    $exclude[]=get_the_ID();
    ?>

            <div id="post-<?php the_ID(); ?>" <?php post_class('grid_11 alpha omega'); ?>>

            <?
            echo posted_by_single();
            ?>
            <div class="grid_11 alpha omega">
                <div id="single_post_title">
                <h1><a href="<? the_permalink(); ?>" title="<? the_title();?>"><? the_title();?></a></h1>

                </div>
                <div class="social_media_balloons">
                <?
                if (function_exists('fbshare_manual')) echo fbshare_manual();
                ?>
                <?
                if (function_exists('tweetmeme')) echo tweetmeme();
                ?>
                </div>

                <div class="grid_11 alpha omega">

                    <?php the_content(); ?>
                    <div id="single_article_selectors">

                    <?php wp_link_pages('before=<div class="single_article_selector">&after=</div>'); ?>
                    <?php wp_link_pages('before=<div class="single_article_selector">&after=</div>&next_or_number=next'); ?>

                    </div>

                    <div class="grid_11 alpha omega" id="social_media_links">
                        <div class="grid_5 alpha">
                            <p><a href="http://www.twitter.com/LakersNation" target="_blank"><img src="/images/twittericon.jpg" alt="Twitter" width="32" height="32" class="alignleft">Follow Lakers Nation </a></p>
                            <p><a href="http://feeds.feedburner.com/LakersNation" target="_blank"><img src="/images/rssicon.jpg" alt="Twitter" width="32" height="32" class="alignleft">Subscribe to Lakers Nation</a></p>
                        </div>
                        <div class="grid_5 omega">
                            <p><a href="http://www.facebook.com/lakersnation" target="_blank"><img src="/images/fbicon.jpg" alt="Twitter" width="32" class="alignleft">Become a Fan on Facebook</a></p>
                            <p><a href="http://itunes.apple.com/us/app/app-of-l-nation/id349346678?mt=8" target="_blank"><img src="/images/iphoneicon.png" alt="Twitter" width="32" height="32" class="alignleft">Download our Free iPhone App</a></p>
                        </div>
                    </div>

                    <div class="shadow_divider"></div>
                </div><!--#post-content-->


            </div><!-- #post-## -->



                <div class="grid_11 alpha omega next_prev_links">
                    <div class="grid_3 alpha">
                        <p>
                            <?php previous_post_link('%link', '&laquo; Previous post') ?>
                        </p>
                    </div><!--.older-->
                    <div class="grid_3 omega" style="float:right; text-align:right;">
                        <p>
                            <?php next_post_link('%link', 'Next Post &raquo;') ?>
                        </p>
                    </div><!--.older-->
                </div><!--.newer-older-->
            <div class="grid_11 alpha omega" id="comments_container">
            <?php comments_template( '', true ); ?>
            </div>
        </div>
    <?php endwhile; ?><!--end loop-->
</div><!--#mainbar-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

您遇到的问题是自定义帖子类型的分页。有一个WordPress.org 上的好帖子 http://wordpress.org/support/topic/pagination-with-custom-post-type-listing?replies=27一些示例和解决方案用于使其发挥作用。

类似的问题已经回答过堆栈溢出 https://stackoverflow.com/questions/3408433/how-to-paginate-results-with-custom-post-types-on-wp


Edit:

我无法使用您提供的代码重现该错误。

See: 自定义帖子类型分页测试 http://press-themes.com/wordpress/gallery/test-gallery-1/

为了创建测试,我采取了以下步骤:

  1. 从主题主页上传并安装白板主题

  2. 将提供的示例代码添加到functions.php以创建帖子类型

  3. 复制提供的代码“图库模板”并将其重命名为 single-gallery.php

(当显示单个帖子类型页面时,模板层次结构会查找 single-PostType.php,然后查找 single.php)

  1. 通过单击图库添加新创建了一个新图库

  2. 使用添加媒体插入了 4 张图像

  3. 已插入<!--nextpage-->每个图像之间

  4. 保存的帖子和更新的永久链接

测试环境

  • WordPress 版本:3.0.1
  • PHP版本:5.2.13
  • 主题:白板
  • 固定链接:/%year%/%monthnum%/%postname%/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

定义了特定 post_type 的帖子内的页面导航在 Wordpress 中不起作用 的相关文章

  • 如何设置 PHP CodeSniffer 来扩展 WordPress 编码标准 + VSCode 中的自动修复错误?

    如何使用扩展 WordPress 编码标准的个人规则为项目设置 PHP CodeSniffer 保存时在 VSCode 中自动修复错误 I have 全局安装 CodeSniffer https github com squizlabs P
  • 将 WordPress 保持在版本控制中 - 主题的单独存储库

    我的 WordPress 项目位于 Git 下 并将 WordPress 作为子模块 我想将主题开发保留在单独的子模块中 但在当前设置内 将主题设置为子模块时遇到一些困难 这是我的文件系统 git master repo index php
  • 通过 WooCommerce 中的管理员编辑订单自动添加或更新自定义费用

    我们有一个特殊情况 我们会在收到订单后向客户开具付款发票 而不是让他们在结账时付款 运费是手动计算的并添加到订单中 然后我们在总额中添加 3 的信用卡费用 为了自动化此过程 我创建了一个脚本 一旦通过后端设置了运费 该脚本就会计算 3 的费
  • WordPress 添加自定义角色以及删除默认角色

    我需要自定义默认角色 因为我只需要 3 个角色 administrator buyer seller 然后我需要添加买家 卖家并删除所有其他默认角色 我应该怎么办 如果有任何现成的代码我可以粘贴进去并且它会起作用 将此代码粘贴到您的主题 f
  • 如何制作自己的 while 循环,就像 WordPress 循环一样?

    我是新来的 也是 PHP 新手 只是想知道如何制作我自己的灵活循环 就像在 WordPress 中一样 注意我不是在谈论 wordpress 我想在我自己的 PHP 应用程序上实现它 我们回顾一下WP 有一段代码是这样的 while hav
  • 限制 WooCommerce 上的域名注册

    如何限制用户电子邮件对 WooCommerce 注册中特定域的访问 我发现这段代码可以做到这一点 但由于某种原因它在 WooCommerce 注册表单上不起作用 如果我进入 WP 登录页面 它就会起作用 任何帮助表示赞赏 function
  • WordPress 按标题获取帖子,例如

    我正在尝试为 WordPress 创建一个小型搜索功能 AJAX 调用应该获取标题类似的所有帖子 quote 是否有可能在内部实现这种情况get posts 功能 别误会我的意思 阿贾克斯工作正常 我的functions php 中有aja
  • 使用 Wordpress 验证 Flask API

    我有两个网站 一个托管大部分内容的 WordPress 博客 我还用 Flask 编写了一个 API 我想在 Wordpress 受密码保护的页面 中使用 API 但我需要在 Flask 响应之前验证请求是否经过身份验证 当我收到对 Fla
  • WordPress 计划事件未在设定时间触发

    在 WordPress 中 我正在创建一个插件 用于向用户发送电子邮件 为此 我使用 WordPresscron工作 所以基本上它要做的就是每小时向用户发送电子邮件 所以我的代码看起来像这样 public function construc
  • 为 foreach() 提供的参数无效..Wordpress

    突然开始出现以下代码的错误 img src title 有时分类 贷款俱乐部 是空的 这可能是问题所在吗 如果是这样 有人可以指出我正确的代码吗 Add if之前的情况foreach
  • WordPress WooCommerce - 使用 WC_Cart 类将可变产品添加到购物车

    我正在尝试将可变产品添加到 WordPress 插件 WooCommerce 的购物车中 到目前为止 我已经能够添加单一 简单的产品 woocommerce gt cart gt add to cart product id quantit
  • 我的设置未保存在 WordPress 主题选项页面中

    我正在尝试创建一个基于 WordPress 设置 API 的主题选项页面 当我在浏览器中检查 options php 页面时 例如http mysite com wordpress wp admin options php http mys
  • 任何插件安装失败 - 无法复制文件错误

    每次我安装一个新的 WordPress 插件时 它都会说无法复制文件和文件地址 有谁知道为什么会这样 我遇到了同样的问题 但就我而言 我是使用 FTP 进行更新 我通过将主机名设置为 localhost 而不是使用 IP 来修复此问题 这是
  • 将具有值的产品属性添加到 Woocommerce 中的产品

    我正在使用此代码添加自定义属性 attributes array array name gt Size options gt array S L XL XXL position gt 1 visible gt 1 variation gt
  • Wordpress - 排除某个类别出现在菜单或侧边栏小部件中

    是否有一个简单的解决方案 例如插件 来排除菜单或侧边栏中出现的类别 我创建了一个名为 视频 的帖子类别 它显示 YouTube 视频 自然 但后来我意识到它们显示在我的 最近帖子 侧边栏中 我正在寻找一种简单的方法来排除它们 任何想法将不胜
  • 计算特定产品类别的购物车商品数量

    我试图仅从 WooCommerce 中的特定产品类别获取购物车中的商品数量 我正在为一家酒厂做一个网站 它有酒精和非酒精产品 所有葡萄酒都属于 葡萄酒 主类别或类别 ID 34 其下有许多子类别和产品 对于属于此类别的任何商品 我需要知道此
  • 如何使用额外标记输出 wp_list_categories

    我目前正在使用下面的脚本在无序列表中输出我的所有 WordPress 类别 如何获得带有额外标记的输出 ul ul 例如 ul li Category 1 rsaquo li li Category 2 rsaquo li ul 代替 ul
  • WordPress 网站的团队开发

    我不是 WordPress 开发人员 但我正在尝试确定团队使用 WordPress 的最佳方式 对于 Rails 项目或大多数其他项目来说 在本地工作并在上游部署很容易 但我的理解是 WordPress 并没有让这变得那么容易 也许这是一个
  • 在 WordPress 中获取作者角色

    我正在开发我的第一个 WP 网站 需要在其帖子旁边显示作者的角色 类似于 吉米 管理员 查看可用的作者元数据 http codex wordpress org Function Reference the author meta http
  • 如何以编程方式获取 WooCommerce 中的所有产品?

    我想获取 WooCommerce 中的所有产品数据 产品 sku 名称 价格 库存数量 可用性等 我可以使用 wp query 来做到这一点吗 这样你就可以通过 wp query 获取所有产品 global wpdb all product

随机推荐