• Resolved sweetandsound

    (@sweetandsound)


    Hello there,

    I’m working on a new theme where i have added a featured gallery on the front page.

    I have used custom fields templates to retrieve featured images and videos which you can scroll through. But I’m having trouble incorporating the excerpt in to it: each time you reload the page it will show the same excerpt from one post on all of them…

    Below is the code i’m using for the gallery, the site (in progress) is here – https://https://nouvellelondon.com/isys/

    Thanks for any help in advance!

    [Code moderated as per the Forum Rules. Please use the pastebin]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter sweetandsound

    (@sweetandsound)

    OOPS, HERE’S THE CODE…

    https://pastebin.com/yyty6N1x

    the code with the excerpt is out side the loop –

    your code runs the main loop to fill an array with data (the excerpt is not part of this loop), then runs a ‘foreach’ loop through this arry ro output the data (the excerpt is in that loop, but will only show the excerpt from the last post in the main loop)

    one possibility: add the excerpt into the array in the main loop, and print it in the foreach loop:

    change this section (line 26/27):

    'subtitle'  => get_post_custom_values('Subtitle')
                                              );

    to:

    'subtitle'  => get_post_custom_values('Subtitle'),
    'excerpt' => get_the_excerpt()
                                              );

    and this (end of line39):

    </span><div class="gallery-excerpt"><span><?php the_excerpt(); ?></span></div></div></div></div>

    to:

    </span><div class="gallery-excerpt"><span><?php print  $_item['excerpt']; ?></span></div></div></div></div>

    (totally untested)

    Thread Starter sweetandsound

    (@sweetandsound)

    perfect, that worked!

    Thanks so much for your help!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘trouble getting excerpt within a custom loop’ is closed to new replies.