Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.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 将活动类添加到自定义发布类型日期存档_Php_Wordpress_Filtering_Archive - Fatal编程技术网

Php 将活动类添加到自定义发布类型日期存档

Php 将活动类添加到自定义发布类型日期存档,php,wordpress,filtering,archive,Php,Wordpress,Filtering,Archive,我正在使用插件按年份创建自定义发布类型日期存档: <?php $args = array( 'post_type' => 'unistused', 'type' => 'yearly', 'format' => 'anchor', ); cptda_get_archives($args); ?> 我还为permalink生成了一个自定义格式,以便在单击年度存档时将其锚定到正确的

我正在使用插件按年份创建自定义发布类型日期存档:

<?php 
    $args = array(
        'post_type' => 'unistused',
        'type' => 'yearly',
        'format' => 'anchor',
        );
    cptda_get_archives($args); 
?>

我还为permalink生成了一个自定义格式,以便在单击年度存档时将其锚定到正确的部分:

//
add_filter ('get_archives_link',
function ($link_html, $url, $text, $format, $before, $after) {
    if ('anchor' == $format) {
        $link_html = "<li class='year-archive'><a href='$url#dreams'>"
                   . "$text"
                   . '</a></li>';
    }
    return $link_html;
}, 10, 6);
//
添加\u筛选器('get\u archives\u link',
函数($link\u html、$url、$text、$format、$before、$after){
如果('anchor'=$format){
$link_html=“
  • ”; } 返回$link_html; }, 10, 6);

    不幸的是,当查看存档页时,自定义结构“锚定”没有将“活动”类添加到永久链接结构中,我无法实现解决方案或实验来实现这一点。如有任何帮助,将不胜感激。

    您可能需要自己将其添加到此自定义函数中:

    add_filter ('get_archives_link',
    function ($link_html, $url, $text, $format, $before, $after) {
        if ('anchor' == $format) {
            
            global $wp;
            $current_url = home_url( add_query_arg( array(), $wp->request ) );
    
            $active_classname =  $current_url === $url ? 'active' : '';
    
            $link_html = "<li class=\"year-archive\"><a href=\"$url#dreams\" class=\"$active_classname\">$text</a></li>";
        }
        return $link_html;
    }, 10, 6);
    
    add_filter('get_archives_link',
    函数($link\u html、$url、$text、$format、$before、$after){
    如果('anchor'=$format){
    全球$wp;
    $current\u url=home\u url(添加查询参数(array(),$wp->request));
    $active\u classname=$current\u url===$url?'active':'';
    $link\u html=“
  • ”; } 返回$link_html; }, 10, 6);
    由于某些原因,此操作返回的是最后一个post permalink url,而不是当前的活动存档url,这很奇怪。请更新我的答案以获得不同的当前url。如果有帮助,请告诉我。