• Hi

    I have inherited a site using the twentyeleven theme – not as a child and I need to create a new widget.

    HOw do I find out what categoies are currently being displayed?

    For instance the site has a link in its menu that says “Astronmy” and when you click it you go to a cateogy pagethat has 5 posts in that category displaying.

    But there might be 50 other posts in that cateogry and i want to create a list. I can use:

    $query = new WP_Query( 'category_name=astronomy' );
    		if ( $query->have_posts() ) {
    			while ( $query->have_posts() ) {
    			$query->the_post();
    			echo '
    <li>' . get_the_title() . '</li>
    ';
    			}
    		}

    So my question is really what function do I use to get it to dunamically put in the category name?

    Thanks in advance

    Edward

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • in a category archive, the cat ID is:

    get_query_var('cat')

    for example, try in the query:

    $query = new WP_Query( array( 'category__in' => array( get_query_var('cat') ) ) );

    or:

    $query = new WP_Query( 'cat=' . get_query_var('cat') );
    Thread Starter maxelcat

    (@maxelcat)

    thanks – really helpful reply – used second one and worked straight away

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘find out what category I am on…’ is closed to new replies.