Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #7714

    BroadScope is great for displaying images beautifully in that huge slideshow it does. Unfortunately, at least in my case, the images have to be manually set on every page and post even if your using that page as the homepage. I post a month’s worth of program highlights near the beginning of each month as posts with the category “Highlights.” I need a specific image from each of those upcoming program highlights to appear in the main slider on the homepage three at a time, link to the post permalink, and then drop off the homepage as the time for each program comes up. I don’t want to have to go in every day or two and manually change those images and captions. I therefore schedule the publication of each post in that category for the specific time that the third post back should disappear. (Did that make any sense?)

    The problem then is how to get the title, link, excerpt, and a specific image from the latest post in a specific category to appear in the big slider on the homepage that’s only designed to hold images and text manually entered into it through the dashboard. (It seems like that would make a great option to add to the Avia framework.)

    Anyway, here’s the code I added to the header.php file of the BroadScope theme. It replaces everything below “<!– ####### END HEAD CONTAINER ####### –>”.

    <?php
    if (is_home('')) :
    echo "<div class='container_wrap' id='featured'><div class='container slideshow_container'><ul class='slideshow'>";
    global $post;
    $offset_counter = 0;
    $container_counter = 1;
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) : setup_postdata($post);
    $args = array( 'numberposts' => 3, 'offset' => $offset_counter, 'category' => 8 );
    $postid = get_the_ID();
    $bg_color_key = 'newslide_bg_color';
    $slide_back_color = get_post_meta($postid, $bg_color_key, true);
    echo "<li class='featured featured_container".$container_counter."' style='background: ".$slide_back_color."'>";
    echo "<a href='";
    echo the_permalink();
    echo "' title='";
    echo the_title();
    echo "'>";
    echo the_post_thumbnail('full');
    echo "</a><div class='feature_excerpt'><h1><a href='";
    echo the_permalink();
    echo "' title='";
    echo the_title();
    echo "'>";
    echo the_title();
    echo "</a></h1><div class='featured_caption'>";
    echo the_excerpt();
    echo "</div></div></li>";
    $offset_counter = $offset_counter + 1;
    $container_counter = $container_counter + 1;
    if ($container_counter > 3) break;
    endforeach;
    echo "</ul><span class='shadow-top'></span><span class='shadow-bottom'></span></div></div>";
    else :
    echo "<div class='container_wrap' id='featured'>";
    echo "<div class='container slideshow_container'>";
    echo avia_inc_display_featured();
    echo "</div>";
    echo "</div>";
    endif;
    ?>

    I know it’s kind of cobbled together quickly, but it displays the latest post stuff on the homepage large slider where I need it without affecting the sliders I use on the other posts and pages, and it still looks like the normal large slider. It does, however, require two additional steps on the individual posts as I put them in through the dashboard:

    1. Use the standard WordPress Featured Image option (You may have to make sure “Featured Image” is enabled in the screen options on the top.) to choose an image from your media library to use for that post in the slider on the homepage. This is separate from the Avia Featured Image options.
    2. Use the Custom Field option (You may have to make sure “Custom Fields” is enabled in the screen options on the top.) to set a custom field called “newslide_bg_color” (without the quotes) and enter the background color you want for that slide in full hex format with the pound/number symbol (ie., #FFFFFF) in the value field.

    Hope this helps someone.

    #59023

    Thank you for the contribution :)

    #59024

    Well, crud. I’ve already hit a snag with this code. It should limit the posts pulled to category number 8. Instead, it’s pulling the latest three posts from any category. I’m having to use the Ultimate Category Excluder plugin to keep the posts in other categories off the main page. Does anyone have any idea why it’s not filtering by category properly?

    #59025

    I’d insert the $args variable before following line (and not within the each loop):

    $myposts = get_posts( $args );

    #59026

    Thanks. You’re absolutely right. I knew it would turn out to be something stupid. I was trying to get_posts with $args before it was even defined. Not only that, but I had residual code left over from my original version when I was just pulling one post at a time–hence the offset counter. Here’s the now working version that doesn’t require a separate plugin to get the right category.

    <?php
    if (is_home('')) :
    echo "<div class='container_wrap' id='featured'><div class='container slideshow_container'><ul class='slideshow'>";
    global $post;
    $container_counter = 1;
    $category_number = 8;
    $args = array( 'numberposts' => 3, 'category' => $category_number );
    $myposts = get_posts( $args );
    foreach( $myposts as $post ) : setup_postdata($post);
    $postid = get_the_ID();
    $bg_color_key = 'newslide_bg_color';
    $slide_back_color = get_post_meta($postid, $bg_color_key, true);
    echo "<li class='featured featured_container".$container_counter."' style='background: ".$slide_back_color."'>";
    echo "<a href='";
    echo the_permalink();
    echo "' title='";
    echo the_title();
    echo "'>";
    echo the_post_thumbnail('full');
    echo "</a><div class='feature_excerpt'><h1><a href='";
    echo the_permalink();
    echo "' title='";
    echo the_title();
    echo "'>";
    echo the_title();
    echo "</a></h1><div class='featured_caption'>";
    echo the_excerpt();
    echo "</div></div></li>";
    $container_counter = $container_counter + 1;
    endforeach;
    echo "</ul><span class='shadow-top'></span><span class='shadow-bottom'></span></div></div>";
    else :
    echo "<div class='container_wrap' id='featured'>";
    echo "<div class='container slideshow_container'>";
    echo avia_inc_display_featured();
    echo "</div>";
    echo "</div>";
    endif;
    ?>

    #59027

    One other thing I forgot about. You have to add the following code to the functions.php file to make use of WordPress thumbnail images even though you’re actually using the full size image here.

    /* Activate native WordPress Post Thumbnails */

    if ( function_exists( 'add_theme_support' ) ) {
    add_theme_support( 'post-thumbnails' );
    }

    #59028

    Glad that it works now :)

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Homepage Slider with Latest Post Images’ is closed to new replies.