I am using a plugin (Recent Posts Widget Extended) to display a series of post links (thumbnails, titles, excerpts etc.) in a column. I would like to style each post link according to a custom field value (fp_post_style) set in the post. This is the page I am working on, the left side column. http://bearleaderchronicle.com/site/frontpage2-test/

The solutions I have found for this don’t seem to work in my situation and I think it may be because they don’t account for the plugin. From this post I got the general idea for a solution http://www.wpbeginner.com/wp-themes/how-to-style-each-wordpress-post-differently/, and from this post I got further details on how this should work How to use custom field to add class to a post?.

If someone could point me in the right direction on this I would be grateful. Thanks!

This is the code I have so far:

<div class="rpwebb-block">
    <?php if ($query->have_posts()) : ?>

            <?php while ($query->have_posts()) : $query->the_post(); ?>

                // start of the new code in question

                <?php $custom_values = get_post_meta($post->ID, 'fp_post_style', true); ?> 
                <?php post_class('class-1 class-2 ' . $custom_variable); ?>

                // end of the new code in question

                $exclude_ids[] = get_the_ID();
                $ext_url = get_post_meta(get_the_ID(), 'RPW_externalurl', true);
                $ext_url = !empty($ext_url) ? $ext_url : get_permalink();
                <li class="rpwe-clearfix">

                    <?php if (has_post_thumbnail() && $thumb == true) { ?>

                        <a href="<?php echo $ext_url; ?>" class="<?php echo ($thumb_width < $thumb_height) ? 'height-alto' : 'no-alto' ?>" title="<?php printf(esc_attr__('Permalink to %s', 'rpwe'), the_title_attribute('echo=0')); ?>" rel="bookmark">
                            if (current_theme_supports('get-the-image'))
                                get_the_image(array('meta_key' => 'Thumbnail', 'height' => $thumb_height, 'width' => $thumb_width, 'image_class' => 'rpwe-alignleft', 'link_to_post' => false));
                                the_post_thumbnail(array($thumb_width, $thumb_height), array('class' => 'rpwe-alignleft', 'alt' => esc_attr(get_the_title()), 'title' => esc_attr(get_the_title())));

                    <?php } ?>

                    <?php if ($date == true) { ?>
                        <span class="rpwe-time"><?php echo get_the_date(); ?></span>
                    <?php } ?>

                    <h3 class="rpwe-title">
                        <a href="<?php echo $ext_url; ?>" title="<?php printf(esc_attr__('Permalink to %s', 'rpwe'), the_title_attribute('echo=0')); ?>" rel="bookmark"><?php the_title(); ?></a>

                    <?php if ($ago == true) { ?>
                        <span class="rpwe-time"><?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . __(' ago', 'rpwe'); ?></span>
                    <?php } ?>

                    <?php if ($excerpt == true) { ?>
                        <div class="rpwe-summary"><p><?php echo blc_excerpt($length); ?></p><p><a href="<?php echo $ext_url; ?>">Read more ></a></p></div>
                    <?php } ?>


            <?php endwhile; ?>
            <?php wp_reset_postdata(); ?>

Read more here: Adding custom class to post via custom field for styling


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: