Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.


in archive.php file, I want to know, which type of archive I i'm in. For example, if I i'm in archive for category Personal I'd like to be able to display it in header of the archive. Of course, I can create file like category-12.php, category-13.php ... and then harcode it in the file, but it doesn't seem to be very good example of code reuse. Thanks for answers.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Inspect get_queried_object().

On an archive for the category Uncategorized you get something like …

stdClass Object
(
    [term_id] => 1
    [name] => Uncategorized
    [slug] => uncategorized
    [term_group] => 0
    [term_taxonomy_id] => 1
    [taxonomy] => category
    [description] => 
    [parent] => 0
    [count] => 8
    [cat_ID] => 1
    [category_count] => 8
    [category_description] => 
    [cat_name] => Uncategorized
    [category_nicename] => uncategorized
    [category_parent] => 0
)

… and on an archive for the tag test

stdClass Object
(
    [term_id] => 18
    [name] => test
    [slug] => test-2
    [term_group] => 0
    [term_taxonomy_id] => 18
    [taxonomy] => post_tag
    [description] => 
    [parent] => 0
    [count] => 1
)

So you can test if a property taxonomy for that object exists and what the value is. Then adjust your template.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.