SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot hephaistion's Avatar
    Join Date
    Oct 2006
    Location
    Polis Chrysochous, Cyprus
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wordpress - Category ID for sidebar of post in single

    Two problems really,

    1. I've installed a 'most popular' widget in the sidebar and wld like to display this in my single pages for the cat of the post. The widget allows for getting most popular within category but this is hard coded and i don't know how to turn the hard coded cat ID into a variable. This is the call:

    PHP Code:
    get_most_viewed_category(3'both'5); 
    parameters: cat ID, pages or posts, limit respectively.

    2. My nav is cat dependant and i have different headers for them. No problem. However, if, for example, I had a category and then clicked on a single post the header reverts to the default rather than inheriting the category specific header. I am clueless.

    All help much appreciated as always,

    M

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The problem is that posts can be in many categories. So which of the many categories a post is in do you want to show popular posts, or a specific header, for?

    Anyway, you can get all the categories a post is in with get_the_category:
    http://codex.wordpress.org/Template_...t_the_category

  3. #3
    SitePoint Zealot hephaistion's Avatar
    Join Date
    Oct 2006
    Location
    Polis Chrysochous, Cyprus
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Dan, at the moment I'm keeping things simple and each post only has one category. However in the future I could envisage listing most popular from parent and most popular from child as well on the single page.

    As far as the header is concerned here's what I have so far:

    PHP Code:
    if (is_category() || is_single()){
     
        if (
    is_category('3') || is_single($post->post_category='3')){
            include(
    TEMPLATEPATH.'/header-cat3.php');
        }
    ... 
    I think what I was trying to do here prob gave a value to the variable rather than checked for cat 3.

  4. #4
    SitePoint Zealot hephaistion's Avatar
    Join Date
    Oct 2006
    Location
    Polis Chrysochous, Cyprus
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just going to try get_the_category just now.

    and thanks

  5. #5
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if (is_category()) {
      if (
    is_category('3')) 
        include(
    TEMPLATEPATH '/header-cat3.php');
    } else if (
    is_single()) {
      
    $category get_the_category();
      
    $catid $category[0]->cat_ID;
      if (
    $catid == 3)
        include(
    TEMPLATEPATH '/header-cat3.php');


  6. #6
    SitePoint Zealot hephaistion's Avatar
    Join Date
    Oct 2006
    Location
    Polis Chrysochous, Cyprus
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that, Dan, I'd probably have had to get back to you for that one. Plugging away with the sidebar at the mo and should be fine. Cheers again. M


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •