Category Images Only Displaying Once on Special Recent Posts (WordPress)

I am using WordPress to put together a blog. I am using the Category Image(s) plugin to put an image for each category above the posts.

The main page is laid out as a big image and excerpt for each article and when you click on it, it takes you to the full article (I am using the ‘Special Recent Posts’ plugin for this). I want category image headers above each big image/excerpt.

Read More

Everything works fine for the first article but after that I get no headers. The reason is because the code I have in my header is calling the ‘Category Image(s)’ php function, which works. Then it calls the ‘Special Recent Posts’ php function which in effect runs the loop to grab the first five most recent articles. It doesn’t run the category images function every time for every article, only the first time.

Here’s the code:

<?php get_header(); ?>

<?php c2c_the_category_image($image_extensions='png gif jpg', $image_dir='/wp-content/images/', $use_name_if_no_image=true, $start_from='begin', $limit=999); ?>

<?php echo do_shortcode("[srp srp_number_post_option='5' srp_thumbnail_option='yes' srp_widget_title_hide_option='yes' srp_post_date_option='no' srp_wdg_excerpt_length='50' srp_wdg_excerpt_length_mode='fullexcerpt']"); ?>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

How can I get it to run the category images function for all the recent posts? Thanks for the help.


EDIT:

I attempting to go into the PHP of the Special Recent Posts plugin but when I attempted to enter the category images code in, it created some critical errors. I’m looking for the easiest solution if it’s out there (I know this isn’t a very simple question to start with). Any help? (I’ve placed a bounty)

Related posts

Leave a Reply

1 comment

  1. Your way of doing things is extremely complicated and convoluted.

    The simplest way that is proved to work is by having images that correspond with either category ID or category slug!

    http://baldino.rs/collection

    As you can see, this is a page that lists all the categories with their images and descriptions.


    I’m having little trouble understading if you want:

    • To have a category image above every post
    • To have a category image AND post image above every post

    I’ll demonstrate the first solution below

    Here is the order in which we will create the blog page:

    1. Name the category images either by slug, or by ID (i recommend ID)
    2. Upload the images to the server – prefferably to the images folder of the theme
    3. Create our custom loop which will display our category image, category name, post title and excerpt

    So the index page (blog page) should look something like this

    <?php get_header();?>
    
    <div id=:content">
        <div id="posts">
        <?php if (have_posts()) : while (have_posts()) : the_post();?>
            <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
                <?php
                $category = get_the_category();?> 
                <img src="<?php bloginfo('template_directory'); ?>/images/<?php echo $category[0]->term_id;?>.jpg"/>
                <h3 class="cat-title"><?php echo $category[0]->cat_name;?></h3>
                <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
                <div class="entry">
                    <?php the_content(); ?>
                </div>
            </div>
        <?php endwhile;endif; ?>    
        </div>
    
    <?php get_sidebar(); ?>
    </div>
    
    <?php get_footer(); ?>
    

    You should really avoid plugins for the simple stuff that is easily solved by the loop

    I recommend that you start reading the WP codex – http://codex.wordpress.org

    Every function, class, reference is documented in detail and it’s very easy to understand.

    If you have more questions, do not hesitate to ask