Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 是否仍要添加rel=”的内容;“下一步”/rel=";“上一次”;变成;页面模板";用Yoast的WordPress搜索引擎优化?_Php_Wordpress - Fatal编程技术网

Php 是否仍要添加rel=”的内容;“下一步”/rel=";“上一次”;变成;页面模板";用Yoast的WordPress搜索引擎优化?

Php 是否仍要添加rel=”的内容;“下一步”/rel=";“上一次”;变成;页面模板";用Yoast的WordPress搜索引擎优化?,php,wordpress,Php,Wordpress,我们的网站目前正在使用“Yoast的WordPress SEO” rel=“next”和rel=“prev”在分类和归档页面上工作正常,但是在我们创建的页面模板中,rel=“next”和rel=“prev”没有显示。 (此页面模板还具有分页功能) 我们的网站结构=>我们有“文章”的帖子类型 在文章中,我们有一个类别 信用卡 现金卡 贷款 等等 因为我希望url是www.sitename.com/loan,而没有。/category/loan 我创建了名为“Loan”的“Page”,并使用Pa

我们的网站目前正在使用“Yoast的WordPress SEO”
rel=“next”
rel=“prev”
在分类和归档页面上工作正常,但是在我们创建的页面模板中,
rel=“next”
rel=“prev”
没有显示。 (此页面模板还具有分页功能)

我们的网站结构=>我们有“
文章
”的帖子类型

在文章中,我们有一个类别

  • 信用卡
  • 现金卡
  • 贷款
  • 等等
因为我希望url是
www.sitename.com/loan
,而没有
。/category/loan

我创建了名为“Loan”的“Page”,并使用
Page Loan.php
作为页面模板来查询帖子类型“Article”类别“Loan”

我想让
rel=“next”
rel=“prev”
也出现在此页面模板中 我想知道到底有没有Yoast使用WordPress SEO来做这件事

或者在插件中有没有修改下面的脚本,使
rel=“next”
rel=“prev”
也出现在页面模板中

我在插件中找到的脚本

    public function adjacent_rel_links() {
    // Don't do this for Genesis, as the way Genesis handles homepage functionality is different and causes issues sometimes.
    /**
     * Filter 'wpseo_genesis_force_adjacent_rel_home' - Allows devs to allow echoing rel="next" / rel="prev" by WP SEO on Genesis installs
     *
     * @api bool $unsigned Whether or not to rel=next / rel=prev
     */
    if ( is_home() && function_exists( 'genesis' ) && apply_filters( 'wpseo_genesis_force_adjacent_rel_home', false ) === false ) {
        return;
    }

    global $wp_query;

    if ( ! is_singular() ) {
        $url = $this->canonical( false, true, true );

        if ( is_string( $url ) && $url !== '' ) {
            $paged = get_query_var( 'paged' );

            if ( 0 == $paged ) {
                $paged = 1;
            }

            if ( $paged == 2 ) {
                $this->adjacent_rel_link( 'prev', $url, ( $paged - 1 ), true );
            }

            // Make sure to use index.php when needed, done after paged == 2 check so the prev links to homepage will not have index.php erroneously.
            if ( is_front_page() ) {
                $url = wpseo_xml_sitemaps_base_url( '' );
            }

            if ( $paged > 2 ) {
                $this->adjacent_rel_link( 'prev', $url, ( $paged - 1 ), true );
            }

            if ( $paged < $wp_query->max_num_pages ) {
                $this->adjacent_rel_link( 'next', $url, ( $paged + 1 ), true );
            }
        }
    }
    else {
        $numpages = 0;
        if ( isset( $wp_query->post->post_content ) ) {
            $numpages = ( substr_count( $wp_query->post->post_content, '<!--nextpage-->' ) + 1 );
        }
        if ( $numpages > 1 ) {
            $page = get_query_var( 'page' );
            if ( ! $page ) {
                $page = 1;
            }

            $url = get_permalink( $wp_query->post->ID );

            // If the current page is the frontpage, pagination should use /base/
            if ( $this->is_home_static_page() ) {
                $usebase = true;
            }
            else {
                $usebase = false;
            }

            if ( $page > 1 ) {
                $this->adjacent_rel_link( 'prev', $url, ( $page - 1 ), $usebase, 'single_paged' );
            }
            if ( $page < $numpages ) {
                $this->adjacent_rel_link( 'next', $url, ( $page + 1 ), $usebase, 'single_paged' );
            }
        }
    }
}

/**
 * Get adjacent pages link for archives
 *
 * @since 1.0.2
 *
 * @param string  $rel                  Link relationship, prev or next.
 * @param string  $url                  the un-paginated URL of the current archive.
 * @param string  $page                 the page number to add on to $url for the $link tag.
 * @param boolean $incl_pagination_base whether or not to include /page/ or not.
 *
 * @return void
 */
private function adjacent_rel_link( $rel, $url, $page, $incl_pagination_base ) {
    global $wp_rewrite;
    if ( ! $wp_rewrite->using_permalinks() ) {
        if ( $page > 1 ) {
            $url = add_query_arg( 'paged', $page, $url );
        }
    }
    else {
        if ( $page > 1 ) {
            $base = '';
            if ( $incl_pagination_base ) {
                $base = trailingslashit( $wp_rewrite->pagination_base );
            }
            $url = user_trailingslashit( trailingslashit( $url ) . $base . $page );
        }
    }
    /**
     * Filter: 'wpseo_' . $rel . '_rel_link' - Allow changing link rel output by WP SEO
     *
     * @api string $unsigned The full `<link` element.
     */
    $link = apply_filters( 'wpseo_' . $rel . '_rel_link', '<link rel="' . esc_attr( $rel ) . '" href="' . esc_url( $url ) . "\" />\n" );

    if ( is_string( $link ) && $link !== '' ) {
        echo $link;
    }
}
公共功能相邻关系链接(){
//不要为Genesis这样做,因为Genesis处理主页功能的方式不同,有时会导致问题。
/**
*过滤器“wpseo\u genesis\u force\u nexting\u rel\u home”-允许开发者允许WP SEO在genesis安装时回显rel=“next”/rel=“prev”
*
*@api bool$未签名是否为rel=next/rel=prev
*/
如果(is_home()&&function_存在('genesis')&&apply_过滤器('wpseo_genesis_force_nexted_rel_home',false)==false){
返回;
}
全局$wp_查询;
如果(!是单数()){
$url=$this->canonical(false、true、true);
如果(是字符串($url)&&$url!=''){
$paged=get_query_var('paged');
如果(0==$paged){
$paged=1;
}
如果($paged==2){
$this->相邻的链接('prev',$url,($paged-1),true);
}
//确保在需要时使用index.php,在paged==2检查后完成,这样主页的上一个链接就不会错误地使用index.php。
如果(是首页()){
$url=wpseo\uXML\uSitemaps\uBase\uURL(“”);
}
如果($paged>2){
$this->相邻的链接('prev',$url,($paged-1),true);
}
如果($paged<$wp\u query->max\u num\u pages){
$this->相邻的链接('next',$url,($paged+1),true);
}
}
}
否则{
$numpages=0;
if(设置($wp\u查询->发布->发布内容)){
$numpages=(substr\u count($wp\u query->post->post\u content',)+1);
}
如果($numpages>1){
$page=get_query_var('page');
如果(!$页){
$page=1;
}
$url=get\u permalink($wp\u query->post->ID);
//如果当前页面是frontpage,分页应使用/base/
如果($this->is\u home\u static\u page()){
$usebase=true;
}
否则{
$usebase=false;
}
如果($page>1){
$this->相邻的链接('prev',$url,($page-1),$usebase,'single_paged');
}
如果($page<$numpages){
$this->nexting_rel_链接('next',$url,($page+1),$usebase,'single_paged');
}
}
}
}
/**
*获取存档的相邻页面链接
*
*@自1.0.2
*
*@param string$rel链接关系,上一个或下一个。
*@param string$url当前存档的未分页url。
*@param string$page要添加到$link标记的$url的页码。
*@param boolean$incl_pagination_base是否包括/page/或不包括。
*
*@返回无效
*/
私有函数相邻链接($rel,$url,$page,$incl_pagination_base){
全球$wp_重写;
如果(!$wp\u rewrite->using\u permalinks()){
如果($page>1){
$url=add_query_arg('paged',$page,$url);
}
}
否则{
如果($page>1){
$base='';
如果($incl_pagination_base){
$base=trailingslahit($wp_rewrite->pagination_base);
}
$url=user\u trailingslashit(trailingslashit($url)。$base.$page);
}
}
/**
*过滤器:“wpseo”.$rel.\u rel\u link”-允许通过wpseo更改链接rel输出
*
*@api string$未签名完整的“\n”);
如果(是字符串($link)&&$link!=''){
echo$link;
}
}

首先,您必须对数据库进行备份。您可以在phpmyadmin上或使用一些为您备份的插件来实现这一点

接下来,你应该做url的事情。你可以从“搜索外观-Yoast SEO”页面的类别中删除类别路径,单击tab Taxonomies,然后删除类别url

关于分页问题,您可以手动输入每个页面上的链接,或者使用php函数获取post类型文章的所有链接,如下所示:

wp_list_pages(array(
'child_of' => $post->post_parent,
'exclude' => $post->ID));