get_post_class example

if ( $lock_holder ) {
            $classes .= ' wp-locked';
        }

        if ( $post->post_parent ) {
            $count    = count( get_post_ancestors( $post->ID ) );
            $classes .= ' level-' . $count;
        } else {
            $classes .= ' level-0';
        }
        ?> <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes$post->ID ) ); ?>"> <?php $this->single_row_columns( $post ); ?> </tr> <?php         $GLOBALS['post'] = $global_post;
    }

    /** * Gets the name of the default primary column. * * @since 4.3.0 * * @return string Name of the default primary column, in this case, 'title'. */
return $context;
        };

        // Use an early priority to so that other 'render_block_context' filters have access to the values.         add_filter( 'render_block_context', $filter_block_context, 1 );
        // Render the inner blocks of the Post Template block with `dynamic` set to `false` to prevent calling         // `render_callback` and ensure that no wrapper markup is included.         $block_content = ( new WP_Block( $block_instance ) )->render( array( 'dynamic' => false ) );
        remove_filter( 'render_block_context', $filter_block_context, 1 );

        // Wrap the render inner blocks in a `li` element with the appropriate post classes.         $post_classes = implode( ' ', get_post_class( 'wp-block-post' ) );
        $content     .= '<li class="' . esc_attr( $post_classes ) . '">' . $block_content . '</li>';
    }

    /* * Use this function to restore the context of the template tags * from a secondary query loop back to the main query loop. * Since we use two custom loops, it's safest to always restore. */
    wp_reset_postdata();

    return sprintf(
        
/** * Displays the classes for the post container element. * * @since 2.7.0 * * @param string|string[] $css_class Optional. One or more classes to add to the class list. * Default empty. * @param int|WP_Post $post Optional. Post ID or post object. Defaults to the global `$post`. */
function post_class( $css_class = '', $post = null ) {
    // Separates classes with a single space, collates classes for post DIV.     echo 'class="' . esc_attr( implode( ' ', get_post_class( $css_class$post ) ) ) . '"';
}

/** * Retrieves an array of the class names for the post container element. * * The class names are many: * * - If the post has a post thumbnail, `has-post-thumbnail` is added as a class. * - If the post is sticky, then the `sticky` class name is added. * - The class `hentry` is always added to each post. * - For each taxonomy that the post belongs to, a class will be added of the format * `{$taxonomy}-{$slug}`, e.g. `category-foo` or `my_custom_taxonomy-bar`. * The `post_tag` taxonomy is a special case; the class has the `tag-` prefix * instead of `post_tag-`. * * All class names are passed through the filter, {@see 'post_class'}, followed by * `$css_class` parameter value, with the post ID as the last parameter. * * @since 2.7.0 * @since 4.2.0 Custom taxonomy class names were added. * * @param string|string[] $css_class Optional. Space-separated string or array of class names * to add to the class list. Default empty. * @param int|WP_Post $post Optional. Post ID or post object. * @return string[] Array of class names. */
Home | Imprint | This part of the site doesn't use cookies.