• Resolved hpatrick777

    (@hpatrick777)


    Hi there,

    I need a plugin which makes post list on my pages with a shortcode. I can see this plugin can do that. But… I also need it that in the list beside of each post the categories the post is in are displayed too. For example if I have a list (radio list) with this posts (names of radios) “Music FM”, “Radio FM”, “Juventus FM” and each radio is in the “Rock” category but the “Music FM” is also in the “Pop” category. If the user see my radio list he/she doesnt see which categories the radios are in. So, I want to show the categories on the list next to each post. Can this plugin do this too?

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

    (@zymeth25)

    Hi,

    It can and it cannot 😉 depending on how you are using it.

    In pure shortcode usage the plugin doesn’t support this. But you can create a custom template and add necessary code to implement the functionality.

    If you switch to using a template, here’s the code that will output a comma separated list of each post’s categories.

    //Show post's categories
    $categories = array_map( function($cat) { return $cat->name; }, get_the_category() );
    $lcp_display_output .= implode( ", ", $categories );
    • This reply was modified 6 years ago by zymeth25.
    Thread Starter hpatrick777

    (@hpatrick777)

    So.. I made a “list-category-posts” folder in the wp-content/themes/my-theme-folder and after I copied the default.php there from the template folder. Actually I copied the templatename.php because before I copied it I renamed it from default.php to templatename.php. Before I copied it into the folder I copied the code what I got from you into the templatename.php file. I think this is what I had to do and I also think it works because the view/style is little bit changed, but still doesnt dislay the categories beside each line. Did I do anything wrong or I missed something? Thank You for your help.

    Plugin Contributor zymeth25

    (@zymeth25)

    So.. I made a “list-category-posts” folder in the wp-content/themes/my-theme-folder and after I copied the default.php there from the template folder. Actually I copied the templatename.php because before I copied it I renamed it from default.php to templatename.php

    That’s all very good. I assume you also added template=templatename to your shortcode.

    Before I copied it into the folder I copied the code what I got from you into the templatename.php file. I think this is what I had to do and I also think it works because the view/style is little bit changed, but still doesnt dislay the categories beside each line.

    Yes, that code was supposed to go into the template file, but the important thing is where you paste it. What interests us here is the part within WP Loop i.e. is responsible for every individual post:

    global $post;
    while ( have_posts() ):
      the_post();
    
      //Start a List Item for each post:
      $lcp_display_output .= "<li>";
    
      //Show the title and link to the post:
      $lcp_display_output .= $this->get_post_title($post, 'h3', 'lcp_post');
    
      //Show comments:
      $lcp_display_output .= $this->get_comments($post);
    
      //Show date:
      $lcp_display_output .= ' ' . $this->get_date($post);
    
      //Show date modified:
      $lcp_display_output .= ' ' . $this->get_modified_date($post);
    
      //Show author
      $lcp_display_output .= $this->get_author($post);
    
      //Custom fields:
      $lcp_display_output .= $this->get_custom_fields($post);
    
      //Post Thumbnail
      $lcp_display_output .= $this->get_thumbnail($post);
    
      /**
       * Post content - Example of how to use tag and class parameters:
       * This will produce:<p class="lcp_content">The content</p>
       */
      $lcp_display_output .= $this->get_content($post, 'p', 'lcp_content');
    
      /**
       * Post content - Example of how to use tag and class parameters:
       * This will produce:<div class="lcp_excerpt">The content</div>
       */
      $lcp_display_output .= $this->get_excerpt($post, 'div', 'lcp_excerpt');
    
      // Get Posts "More" link:
      $lcp_display_output .= $this->get_posts_morelink($post);
    
      //Close li tag
      $lcp_display_output .= '</li>';
    endwhile;

    As you can see there is code responsible for rendering date, author, etc. You need to paste the code I gave you into this section of the template. For instance, if you’d like the categories to be displayed at the very end, put the new code just above

    //Close li tag
    $lcp_display_output .= '</li>';
    • This reply was modified 6 years ago by zymeth25.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘displeyed categories in the list’ is closed to new replies.