2013-08-26 2 views
8

archive.php 페이지에서 어떻게 사용자 정의 카테고리 이름이나 ID를 가져올 수 있습니까? 따라서 해당 페이지 템플릿에있을 때 어떤 맞춤 카테고리 게시물이 표시되는지 어떻게 알 수 있습니까?archive.php 페이지에서 사용자 정의 카테고리 이름 또는 ID 가져 오기 Wordpress

+0

"맞춤 카테고리 이름"에 대한 용어는 맞춤 분류 또는 표준 카테고리에 추가 된 용어에 추가 된 용어입니까? – iEmanuele

+1

나는 맞춤식 분류 용어를 뜻합니다. – user2688562

답변

32

현재 쿼리 된 개체를 검색하려면 get_queried_object();을 사용하십시오. 분류 체계의 용어 경우

다음

//Custom taxonomy is project_type, custom term is web-design 
$obj = get_queried_object(); 

echo '<pre>'; 
print_r($obj); 
echo '</pre>'; 

디스플레이 :

stdClass Object 
(
    [term_id] => 56 
    [name] => Web Design 
    [slug] => web-design 
    [term_group] => 0 
    [term_taxonomy_id] => 56 
    [taxonomy] => project_type 
    [description] => Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 
    [parent] => 0 
    [count] => 0 
) 

는 희망이 도움이!

2

이 코드가 도움이되는지 확인 하시겠습니까 ??

if (is_single()) { 
$cats = get_the_category(); 
$cat = $cats[0]; // let's just assume the post has one category 
} 
else { // category archives 
$cat = get_category(get_query_var('cat')); 
} 
$cat_id = $cat->cat_ID; 
$cat_name = $cat->name; 
$cat_slug = $cat->slug; 
0

카테고리 이름을 얻기 위해이 코드를 사용해보세요 !! $ cat_name = single_cat_title ('', false); 당신은 예를 들어, archive.php 페이지에서 현재의 범주를 표시하려는 경우

1

, 당신의 URL 인 경우 :

:

다음
www.sitename.com/category/design 

다음 사용하는 것이 '디자인'에코 h가있는 카테고리 '디자인'을 표시

<h1 class="page-heading"><?php single_cat_title(); ?></h1> 

: 내 아카이브 페이지에서

single_cat_title(); 

나는 다음이 1 태그. 나는 이것이 누군가를 돕기를 바랍니다.