• Resolved toumeral

    (@toumeral)


    I want to pull the second post from the specific categories to be used in the slider on my site. Currently it pulls only the first post from the categories I choose to display on the slider. I was wondering if there is a way to display only the second most recent post in the slider. Below is the code for the slider. Thanks!

    <!--BEGIN FEATURED POSTS-->
    <ul id="slider-nav">
    <?php $i = 0; $slider_query = new WP_Query("showposts=4&cat=14,16,13,18"); ?>
    <div id="slider-posts">
    <?php global $wp_query;query_posts(array_merge(array('offset' => 1),$wp_query->query));?>
    <?php $i++; ?>
    <div class="slide">
    <div class="slide-thumbnail">
    <?php get_the_image( array( 'custom_key' => array( 'photo-medium' ), 'default_size' => '590x400', 'width' => '590', 'height' => '400', 'image_class' => '' ) ); ?>
    </div>
    <div class="slide-details">
    <h2>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></h2>
    <div class="description">
    <p><?php echo substr(get_the_excerpt(),0,180); ?>...</p>
    </div>
    </div>
    <div class="clear"></div>
    </div>
    <?php endwhile; wp_reset_query(); $i = 0; ?>
    </div>

    [please mark any posted code according to forum guidelines – https://codex.www.ads-software.com/Forum_Welcome#Posting_Code ]

Viewing 8 replies - 1 through 8 (of 8 total)
  • generally, try and add the ‘offset’ into the WP_Query args:

    $slider_query = new WP_Query("showposts=4&cat=14,16,13,18&offset=1");

    is your code working?
    there seems to be no ‘while( $slider_query->have_posts() )‘ and it closes with a </div> instead of </ul> (?)

    what is the original unedited code of the slider?

    Thread Starter toumeral

    (@toumeral)

    Yes this code is working and includes no edits from me for this theme. I have attempted to us the ‘offest’ into the WP_query, but it essentially deletes my homepage.

    Again, this is the unedited code.

    what theme is that and where did you download it from?

    is what you posted, the full code of the template?

    if not, could you paste the full code into a pastebin and post the link to it here?
    https://codex.www.ads-software.com/Forum_Welcome#Posting_Code

    Thread Starter toumeral

    (@toumeral)

    This is the ‘Berlin’ theme from Graph Paper Press. I asked them for help on this issue, but for some reason was met with a lot of resistance.

    https://thefirsteleven.com/

    That is the link to my site as it stands now. As you can see, some posts get posted both in the slider and in a thumbnail below. I see two solutions:

    1) Post only second most recent post from categories designated in slider.
    2) Bypass most recent post in thumbnails of categories at bottom of page for those categories that are also in the slider.

    I prefer the second option as that means the most recent and important posts will be in slider. Though, if only option one can be achieved I won’t have any qualms.

    Below is the code as it stands now for my homepage. I have tried using the ‘offset’ command in both the slider and the thumbnail categories at the bottom of the page, both without success.

    I hope I explained my issue well enough. I appreciate your help more than you know. Thanks!

    https://pastebin.com/kiRvQmQU

    change line 20:

    <?php while ($slider_query->have_posts() && $i<=4) : $slider_query->the_post(); $do_not_duplicate = $post->ID; ?>

    to:

    <?php $do_not_duplicate = array(); while ($slider_query->have_posts() && $i<=4) : $slider_query->the_post(); $do_not_duplicate[] = $post->ID; ?>

    (that will collect all post IDs shown in the slider)

    then change line 95:

    <?php query_posts("showposts=1&cat=$category "); ?>

    to:

    <?php query_posts( array('posts_per_page' => 1, 'cat' => $category, 'post__not_in' => $do_not_duplicate) ); ?>

    then change line 106:

    <?php query_posts("showposts=2&offset=1&cat=$category"); ?>

    to:

    <?php query_posts( array('posts_per_page' => 2, 'offset' => 1, 'cat' => $category, 'post__not_in' => $do_not_duplicate) ); ?>

    ref:
    https://codex.www.ads-software.com/The_Loop
    (particular https://codex.www.ads-software.com/The_Loop#Multiple_Loops_in_Action the part after Note for Multiple Posts in the First Category)
    https://codex.www.ads-software.com/Class_Reference/WP_Query

    Thread Starter toumeral

    (@toumeral)

    There are honestly so many superlatives I could use to express my gratitude for that. That was above my head and that worked to perfection. Thank you so, so incredibly much alchymyth. You’re the man.

    you are welcome;

    if this is all sorted, please mark the topic as ‘resolved’ – thanks.

    Thread Starter toumeral

    (@toumeral)

    Thanks again.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Pulling Second Post from Category’ is closed to new replies.