dongwuqi4243 2015-07-24 05:56
浏览 60
已采纳

当前URL添加和删除term-> slug

I have some issues with add/delete taxonomy from url.

$arch_postID - i get posts ID's from loop on current archive page.

How it works:

1 - when i push <a class="cat-hide-link" href="'. $URI .''. $res_slug[$f] .'" >+</a> i'm aditing to page URL appropriate '+slug'

2 - When i push <a href="'. $linkk .'" >-</a> i'm removing appropriate '+slug' from current url( if it's exist )

Now code working like that:

I have 3 slugs to add, "other-1", "other-2", "other-3". I add them one by one, first- "other-1", last- "other-3"

Current URL be like - "domain/other/other-1+other-2+other-3"

When im trying to push "-" on slug "other-1" i get back whole current URL

When im pushing "-" on slug "other-2" i get URL - "domain/other/other-1". But not URL - "domain/other/other-1+other-3"

When im pushng "-" on "other-3" i get right back value. URL - "domain/other/other-1+other-2"

Some one, Help pls! Thanks for your time!

$Path=$_SERVER['REQUEST_URI'];
    $Prev_path=$_SERVER['HTTP_REFERER'];
    $URI='http://gradrich.tmweb.ru'.$Path;
    global $arch_postID;
    if ( !empty($arch_postID) && is_archive() ){ 
        for($i = 0; $i <= $b-1; $i++){  //goes a 100 time from 0, to show all parameters from wp_get_post_terms array
        $terms_array = wp_get_post_terms($arch_postID[$i],'other');

        for($a = 0; $a <= 100; $a++){
        $terms_name[] = $terms_array[$a]->name; // create array of terms->name
        $terms_slug[] = $terms_array[$a]->slug; // create array of terms->slug

        }  
        }   

        $result_name = array_unique($terms_name); // check name array for unique variables 
        $result_slug = array_unique($terms_slug); // check slug array for unique variables 

        for($f = 0, $s = 0; $f <= count($terms_name), $s <= count($terms_slug); $f++, $s++){ // do loop for all unique variables

        if(!empty($result_name[$f]) && !is_category() || !empty($result_slug[$s]) && !is_category() ){//check if variables not empty than get proper name and slug from two arrays

        $res_slug[$f] = '+'.$result_slug[$s].'';
        $linkk[$f] = substr($URI, 0, strrpos($URI, $res_slug[$f]));
        echo '<div class="tagCloud-cover" id="cat-hide-'. $s .'"><a class="cat-hide-link" href="'. $URI .''. $res_slug[$f] .'" >+</a>';
        echo '<a href="'. get_post_type_archive_link() .''. $result_slug[$s] .'" rel="tag">' . $result_name[$f] . '</a>';   
        echo '<a href="'. $linkk .'" >-</a></div>'; 

        if (false !== strpos($Path, $result_slug[$s])) {
        echo '<style>#cat-hide-'. $s .'{display:none;}</style>';
        echo '<div class="tagCloud-cover" id="cat-hide"><span class="cat-hide-link" >+</span>';
        echo '<a href="'. get_post_type_archive_link() .''. $result_slug[$s] .'" rel="tag">' . $result_name[$f] . '</a>';
        echo '<a href="'. $linkk[$f] .'" >-</a></div>';          
        }
        } else{
        }
        }  
    }
  • 写回答

1条回答 默认 最新

  • douguazhi5966 2015-07-29 15:36
    关注

    I find solution, what was used to devide current URL for finding added tags->slug, delete it and get new URL:

        $only_tags = substr($URI, strrpos($URI,'/')+1);
        $tags = explode('+',$only_tags);
        $tags_string = implode('+',$tags);
    

    Working code below:

      for($f = 0, $s = 0; $f <= count($terms_name), $s <= count($terms_slug); $f++, $s++){
    
            if(!empty($result_name[$f]) && !is_category() || !empty($result_slug[$s]) && !is_category() ){
    
            $only_tags = substr($URI, strrpos($URI,'/')+1);
            $tags = explode('+',$only_tags);
    
            foreach ($tags as $t_key=>$t_value) {
            if ($t_value == $result_slug[$s]) unset ($tags[$t_key]);
             }
            $tags_string = implode('+',$tags);
    
            echo '<div class="tagCloud-cover" id="cat-hide-'. $s .'"><a class="cat-hide-link" href="'. $URI .'+'. $result_slug[$s] .'" >+</a>';
            echo '<a href="'. $result_slug[$s] .'" rel="tag">' . $result_name[$f] . '</a>'; 
            echo '<a href="'. $tags_string .'" >-</a></div>';
            if (false !== strpos($Path, $result_slug[$s])) {
            echo '<style>#cat-hide-'. $s .'{display:none;}</style>';
            echo '<div class="tagCloud-cover" id="cat-hide"><span class="cat-hide-link" >+</span>';
            echo '<a href="'. $result_slug[$s] .'" rel="tag">' . $result_name[$f] . '</a>';
            echo '<a href="'. $tags_string .'" >-</a></div>'; 
    
            }
    
            }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B