具有定制贴子式循环案例页面复制的页面模板

时间:2017-03-30 作者:Husam Alfas

使用此参数创建的自定义帖子类型

\'labels\' => $labels,
\'hierarchical\' => false,
\'description\' => \'Custom post type for question and answer\',
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'thumbnail\' ),
\'public\' => false,
\'show_ui\' => true,
\'show_in_menu\' => false,
\'menu_position\' => 24,
\'menu_icon\' => \'dashicons-editor-help\',
\'show_in_nav_menus\' => false,
\'publicly_queryable\' => false,
\'exclude_from_search\' => true,
\'has_archive\' => false,
\'query_var\' => false,
\'can_export\' => true,
\'rewrite\' => false,
\'capability_type\' => \'post\'
页面模板中显示此自定义帖子类型的循环(续PS/1):在wordpress阅读设置中显示100页的帖子(续PS/2):此永久链接已用于此自定义帖子类型的存档页面

\'post_type\' => \'question\', \'posts_per_page\' => -1
我有24个帖子。

问题是访问时%link/thispage/page/2/, %link/thispage/page/3/, %link/thispage/page/4/, %link/thispage/page/5/, %link/thispage/page/6/, %link/thispage/page/7/, %link/thispage/page/8/ 即使%link/thispage/page/100/

如果没有更多的帖子要显示,如何避免自定义帖子类型的子页面,以及如何避免包含显示所有1篇帖子的自定义帖子类型循环的页面的子页面

2 个回复
最合适的回答,由SO网友:Husam Alfas 整理而成

will正如我回答dipen的一样,这是一个wordpress超级超级SEO bug。。。尝试在wordpress中创建的任何页面,并添加链接/第/3页/至/第/100000000页/它将具有与我自己的竞争对手发送到索引的内容相同的内容,并真正损害我的serp结果。

Wordpress Infinity loop感谢杰夫·斯塔尔-https://perishablepress.com

global $posts, $numpages;

$request_uri = $_SERVER[\'REQUEST_URI\'];

$result = preg_match(\'%\\/(\\d)+(\\/)?$%\', $request_uri, $matches);

$ordinal = $result ? intval($matches[1]) : FALSE;

if(is_numeric($ordinal)) {

    // a numbered page was requested: validate it
    // look-ahead: initialises the global $numpages

    setup_postdata($posts[0]); // yes, hack

    $redirect_to = ($ordinal < 2) ? \'/\': (($ordinal > $numpages) ? "/$numpages/" : FALSE);

    if(is_string($redirect_to)) {

        // we got us a phantom
        $redirect_url = get_option(\'home\') . preg_replace(\'%\'.$matches[0].\'%\', $redirect_to, $request_uri);

        // if page = 0 or 1, redirect permanently
        if($ordinal < 2) {
            header($_SERVER[\'SERVER_PROTOCOL\'] . \' 301 Moved Permanently\');
        } else {
            header($_SERVER[\'SERVER_PROTOCOL\'] . \' 302 Found\');
        }

        header("Location: $redirect_url");
        exit();

    }
}

SO网友:dipen patel

我认为此问题与代码中的has\\u archive设置为false有关。因此,您需要在register\\u post\\u type()“has\\u archive”=>true中将“has\\u archive”设置为true,然后请在更新该属性后刷新永久链接。我相信这会有所帮助。此外,您可能需要为此CPT的存档创建自定义模板,请检查codex.

相关推荐