Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.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
Wordpress 将wpseo_next_rel_链接筛选器应用于特定类别_Wordpress_Function_Filter - Fatal编程技术网

Wordpress 将wpseo_next_rel_链接筛选器应用于特定类别

Wordpress 将wpseo_next_rel_链接筛选器应用于特定类别,wordpress,function,filter,Wordpress,Function,Filter,我在我的网站上使用来自yoast的wp seo插件,我只想在特定类别中操作这个过滤器 这是我尝试的方式,但不起作用。我该怎么做 add_filter('wpseo_next_rel_link', 'my_custom_rel_next'); function my_custom_rel_next($my_c_next_link) { //get the last part of the URL $parts = parse_url($url); parse_str($pa

我在我的网站上使用来自yoast的wp seo插件,我只想在特定类别中操作这个过滤器

这是我尝试的方式,但不起作用。我该怎么做

add_filter('wpseo_next_rel_link', 'my_custom_rel_next');
function my_custom_rel_next($my_c_next_link) {
    //get the last part of the URL
    $parts = parse_url($url);
    parse_str($parts['query'], $query);
    $page_number_var = $_GET['cpage'];
    $page_number_plus_1_var = $_GET['cpage']+1;
    // get url section ex: "mystars", "studios", etc..
    $segments = explode('/', trim(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH), '/'));
    $numSegments = count($segments); 
    $currentSegment = $segments[$numSegments - 1];
    // define links to show
        // define links to show
        $next_link_2_next_pages = '<link rel="next" href="'.get_site_url().'/'.$currentSegment.'/?cpage='.$page_number_plus_1_var.'" />';
        if (is_category(561)) {
        return $next_link_2_page_1;
        }else{
        return 'regular next_link outputted by the plugin'; 
        }
}
add_filter('wpseo_next_rel_link','my_custom_rel_next');
函数my_custom_rel_next($my_c_next_link){
//获取URL的最后一部分
$parts=parse_url($url);
parse_str($parts['query',$query);
$page\u number\u var=$\u GET['cpage'];
$page_number_plus_1_var=$\u GET['cpage']+1;
//获取url部分例如:“mystars”、“studios”等。。
$segments=explode('/',trim(解析url($\\服务器['REQUEST\\ URI'],PHP\\ url\\路径),'/');
$numSegments=计数($segments);
$currentSegment=$segments[$numSegments-1];
//定义要显示的链接
//定义要显示的链接
$next_link_2_next_pages='';
如果(是_类(561)){
返回$next_link_2_page_1;
}否则{
返回“插件输出的常规下一个链接”;
}
}
正确的操作方法:

add_filter( 'wpseo_head', 'custom_change_wpseo_next' , '20' );
function custom_change_wpseo_next( $link ) {
if ( is_page_template(array('page-1.php', 'page-2.php', 'page-3.php')) ) {
 add_filter( 'wpseo_canonical', '__return_false' );
            if ( class_exists('WPSEO_Frontend') ) {
                    $frontend = WPSEO_Frontend::get_instance();
                    global $wp_query;
      if ( get_query_var('paged') ) {
          $paged = get_query_var('paged');
                            } elseif ( get_query_var('page') ) {
                                $paged = get_query_var('page');
                            } else {
                                $paged = 1;
                                echo '<link rel="canonical" href="'.get_pagenum_link( $paged).'" />' . PHP_EOL;
                                echo '<link rel="next" href="'.get_pagenum_link( $paged +1 ).'" />' . PHP_EOL;  
                            }
                            if ( $paged > 1 ) {
                                    //$link0 = '<meta name="robots" content="noindex,follow"/>' . PHP_EOL;
                                    echo '<link rel="canonical" href="'.get_pagenum_link( $paged).'" />' . PHP_EOL; 
                                    echo '<link rel="prev" href="'.get_pagenum_link( $paged -1 ).'" />' . PHP_EOL;  
                                    echo '<link rel="next" href="'.get_pagenum_link( $paged +1 ).'" />' . PHP_EOL;  
                            }
                    }
}
    echo $link;
}
add_filter('wpseo_head','custom_change_wpseo_next','20');
函数自定义\u更改\u wpseo\u下一步($link){
if(是页面模板(数组('page-1.php','page-2.php','page-3.php')){
添加过滤器('wpseo'u canonical','uuuu return'u false');
如果(类_存在('WPSEO_前端')){
$frontend=WPSEO_frontend::get_instance();
全局$wp_查询;
if(获取查询变量('paged')){
$paged=get_query_var('paged');
}elseif(获取查询变量('page')){
$paged=get_query_var('page');
}否则{
$paged=1;
回音“.PHP_EOL;
回音“.PHP_EOL;
}
如果($paged>1){
//$link0=''.PHP\u EOL;
回音“.PHP_EOL;
回音“.PHP_EOL;
回音“.PHP_EOL;
}
}
}
echo$link;
}
根据需要进行调整。

正确的操作方法:

add_filter( 'wpseo_head', 'custom_change_wpseo_next' , '20' );
function custom_change_wpseo_next( $link ) {
if ( is_page_template(array('page-1.php', 'page-2.php', 'page-3.php')) ) {
 add_filter( 'wpseo_canonical', '__return_false' );
            if ( class_exists('WPSEO_Frontend') ) {
                    $frontend = WPSEO_Frontend::get_instance();
                    global $wp_query;
      if ( get_query_var('paged') ) {
          $paged = get_query_var('paged');
                            } elseif ( get_query_var('page') ) {
                                $paged = get_query_var('page');
                            } else {
                                $paged = 1;
                                echo '<link rel="canonical" href="'.get_pagenum_link( $paged).'" />' . PHP_EOL;
                                echo '<link rel="next" href="'.get_pagenum_link( $paged +1 ).'" />' . PHP_EOL;  
                            }
                            if ( $paged > 1 ) {
                                    //$link0 = '<meta name="robots" content="noindex,follow"/>' . PHP_EOL;
                                    echo '<link rel="canonical" href="'.get_pagenum_link( $paged).'" />' . PHP_EOL; 
                                    echo '<link rel="prev" href="'.get_pagenum_link( $paged -1 ).'" />' . PHP_EOL;  
                                    echo '<link rel="next" href="'.get_pagenum_link( $paged +1 ).'" />' . PHP_EOL;  
                            }
                    }
}
    echo $link;
}
add_filter('wpseo_head','custom_change_wpseo_next','20');
函数自定义\u更改\u wpseo\u下一步($link){
if(是页面模板(数组('page-1.php','page-2.php','page-3.php')){
添加过滤器('wpseo'u canonical','uuuu return'u false');
如果(类_存在('WPSEO_前端')){
$frontend=WPSEO_frontend::get_instance();
全局$wp_查询;
if(获取查询变量('paged')){
$paged=get_query_var('paged');
}elseif(获取查询变量('page')){
$paged=get_query_var('page');
}否则{
$paged=1;
回音“.PHP_EOL;
回音“.PHP_EOL;
}
如果($paged>1){
//$link0=''.PHP\u EOL;
回音“.PHP_EOL;
回音“.PHP_EOL;
回音“.PHP_EOL;
}
}
}
echo$link;
}

根据需要进行调整。

代码中是否有“我的自定义关系”下一步功能?当执行钩子时,筛选器将尝试调用该函数。@我不确定是否理解您的意思。你能澄清一下吗?当然!在要挂接到
wpseo\u next\u rel\u链接的
add\u filter
定义中,指定回调函数为
my\u custom\u rel\u next
,这是WordPress在应用过滤器时将使用的函数。我希望看到一个定义了
函数my_custom_rel_next($link){}
的函数来处理修改链接。我的猜测是,
add\u filter
调用下的所有内容都应该包装在该函数中,或者您在其他地方定义了该函数,而该函数没有包含在上述问题中。@bswatson抱歉。。。那是我的脊椎骨缺失的一部分。我编辑了上面的问题。谢谢在那次更改之后,您是否仍然对上面的代码有问题?代码中是否有my_custom_rel_next函数?当执行钩子时,筛选器将尝试调用该函数。@我不确定是否理解您的意思。你能澄清一下吗?当然!在要挂接到
wpseo\u next\u rel\u链接的
add\u filter
定义中,指定回调函数为
my\u custom\u rel\u next
,这是WordPress在应用过滤器时将使用的函数。我希望看到一个定义了
函数my_custom_rel_next($link){}
的函数来处理修改链接。我的猜测是,
add\u filter
调用下的所有内容都应该包装在该函数中,或者您在其他地方定义了该函数,而该函数没有包含在上述问题中。@bswatson抱歉。。。那是我的脊椎骨缺失的一部分。我编辑了上面的问题。谢谢在那次更改之后,您对上面的代码仍然有问题吗?