php - Wordpress - Getting the queried type (Category, archive, author etc) -


e.g 1. when clicks "curators" category, bring them curators category page , display posts of "curators" category own featured image. or 2. when clicks author "john", bring them john page posts , display "john" featured image.

question how can retrieve "curators" or "john" want display featured image different pages. extract "john" go folder find john.jpg , display archived page header image. or go "explorers" category page , display category page explorer featured image.

i got it's category:

<? $cat = get_query_var('cat'); $yourcat = get_category ($cat); ?> #headerimg { background-image: url(<?php echo       ithaka_directory_uri() .'/images/'. $yourcat-    >slug .'.jpg'?>); } 

did pgk told me to: get_queried_object(); not working.

<?php $term = $wp_query->get_queried_object(); ?>  #headerimg { background-image: url(<?php echo ithaka_directory_uri() .'/images/'. $term .'.jpg'?>); } 

it return me "fatal error: call member function get_queried_object() on non-object in /home/departur/public_html/wp-content/themes/ithaka/inc/custom-header.php on line 97
"

you can use get_queried_object() function link:

from codex

retrieve currently-queried object. example:

if you're on single post, return post object

if you're on page, return page object

if you're on archive page, return post type object

if you're on category archive, return category object

if you're on author archive, return author object

etc.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -