当前 URL 添加和删除术语->slug
Current URL add and remove term->slug
我对来自 url 的 add/delete 分类有一些问题。
$arch_postID - 我从当前存档页面的循环中获取帖子 ID。
工作原理:
1 - 当我按下 <a class="cat-hide-link" href="'. $URI .''. $res_slug[$f] .'" >+</a>
时,我正在编辑页面 URL 适当的 '+slug'
2 - 当我按下 <a href="'. $linkk .'" >-</a>
时,我正在从当前 url(如果存在)
中删除适当的“+slug”
现在代码像这样工作:
我有 3 个鼻涕虫要添加,"other-1"、"other-2"、"other-3"。我一个一个地添加它们,首先- "other-1",最后- "other-3"
当前 URL 就像 - "domain/other/other-1+other-2+other-3"
当我试图在 slug "other-1" 上按下“-”时,我恢复了整个电流 URL
当我在 slug "other-2" 上按下“-”时,我得到 URL - "domain/other/other-1"。但不是 URL - "domain/other/other-1+other-3"
当我在 "other-3" 上推送“-”时,我得到正确的返回值。 URL - "domain/other/other-1+other-2"
有人,请帮忙!感谢您的宝贵时间!
$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{
}
}
}
我找到了解决方案,用于划分当前 URL 的内容用于查找添加的标签->slug,将其删除并获得新的 URL:
$only_tags = substr($URI, strrpos($URI,'/')+1);
$tags = explode('+',$only_tags);
$tags_string = implode('+',$tags);
下面的工作代码:
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>';
}
}
我对来自 url 的 add/delete 分类有一些问题。
$arch_postID - 我从当前存档页面的循环中获取帖子 ID。
工作原理:
1 - 当我按下 <a class="cat-hide-link" href="'. $URI .''. $res_slug[$f] .'" >+</a>
时,我正在编辑页面 URL 适当的 '+slug'
2 - 当我按下 <a href="'. $linkk .'" >-</a>
时,我正在从当前 url(如果存在)
现在代码像这样工作:
我有 3 个鼻涕虫要添加,"other-1"、"other-2"、"other-3"。我一个一个地添加它们,首先- "other-1",最后- "other-3"
当前 URL 就像 - "domain/other/other-1+other-2+other-3"
当我试图在 slug "other-1" 上按下“-”时,我恢复了整个电流 URL
当我在 slug "other-2" 上按下“-”时,我得到 URL - "domain/other/other-1"。但不是 URL - "domain/other/other-1+other-3"
当我在 "other-3" 上推送“-”时,我得到正确的返回值。 URL - "domain/other/other-1+other-2"
有人,请帮忙!感谢您的宝贵时间!
$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{
}
}
}
我找到了解决方案,用于划分当前 URL 的内容用于查找添加的标签->slug,将其删除并获得新的 URL:
$only_tags = substr($URI, strrpos($URI,'/')+1);
$tags = explode('+',$only_tags);
$tags_string = implode('+',$tags);
下面的工作代码:
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>';
}
}