• Resolved VanW

    (@vanw)


    Hello,
    First of all thank you for great plugin, I’ve been using it for a long time…

    I have question.
    In case that two or more categories are selected to show posts, is there a way to add a specific class (identifing category of post origin) to the post? Ideally to

    • itself?

      Thank you very much for your answer

      with regards
      Van

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor zymeth25

    (@zymeth25)

    Hi @vanw,

    Right now it is only possible to do this with post tags, using the tags_as_class shortcode parameter. It is not possible to do what you want with the shortcode only, but you could do it using a custom template.

    Thread Starter VanW

    (@vanw)

    Hello zymeth25,
    Thank you for your reply,
    I’ve already started working on my template, however still can’t find the right solution.
    This is what I have, but doesn’t work.(inside the loop)

      if ( in_category( 'webinar' )) {
      $lcp_display_output .= '<li id="webinar" class="webinar">';
    } elseif ( in_category( 'events' ) {
      $lcp_display_output .= '<li id="event" class="event">';
    } else {
      $lcp_display_output .= '<li id="other" class="other">';
      }
        endif;

    can you please suggest solution?

    with regards
    Van

    Plugin Contributor zymeth25

    (@zymeth25)

    First of all, using categories as id is a very bad idea because many posts can have same category. Only one HTML element should have a given id, but same class can be assigned to many different elements. So I suggest you use classes only for this purpose.

    Now, this code should do just what you want (inside The Loop):

    $categories = get_the_category();
    $lcp_display_output .= '<li class="' . $categories[0]->slug . '">';
    Thread Starter VanW

    (@vanw)

    zymeth25
    Thank you for your help. The IDs was leftover from previous testing.
    Your answer helped.

    Thank you for your time

    with regards

    Van

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Adding category class if more categories selected’ is closed to new replies.