• Resolved SchweizerSchoggi

    (@schweizerschoggi)


    Dear Héctor

    I am using your plugin to display the 5 most popular posts via shortcode inside a slider.
    For some reason I need to have access to the post classes.

    The relevant part where I am struggeling:

    [wpp post_html='<div class="[POST CLASSES HERE]">do other stuff</div>']

    How can I achieve this?

    I am currently trying like this in functions.php

    if ( false !== strpos($html, '{postclass}') ) {
         $postclasses = get_post_class( $post_id );
               
         // Replace {postclass} with the value of $postclasses
         $html = str_replace( '{postclass}', implode( ' ', $postclasses ), $html );                        }

    And I am getting a few classes. But for example I dont get the tag- classes of the individual post.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    According to the documentation you should be passing two parameters to the get_post_class() function, not one as you did ??

    The first parameter is a string (text) or an array of strings with the additional classnames that you wish to add to the post (eg. 'foo bar' or array('foo', 'bar'). If you don’t want to add new classnames then you can pass an empty string.

    The second parameter is the post / page ID itself. If you don’t provide it (and you didn’t) the function will try to use the post / page ID of the current page in this instance, which is not what you want.

    So, try changing the $postclasses line to this and check again:

    $postclasses = get_post_class( '', $post_id );

    Thread Starter SchweizerSchoggi

    (@schweizerschoggi)

    Oh dear… of course you are right. I didn’t recognize it, because I DID get classes, just not all that I was expecting. So that haven’t been the classes of each post but from the current page I guess. (Or something else ?? )

    So yeah, sure, my fault… thanks for pointing this out!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to display post classes?’ is closed to new replies.