[Resolved] Excerpt Action Hook

Home Forums Support [Resolved] Excerpt Action Hook

Home Forums Support Excerpt Action Hook

Viewing 15 posts - 1 through 15 (of 39 total)
  • Author
    Posts
  • #918051
    Andy

    Hi,
    Is there any way of inserting an opening/closing shortcode tag before/after the excerpt shown on archive pages? – perhaps with some kind of hook?. Would also need to do the same for WP Show Posts lists.

    #918060
    Leo
    Staff
    Customer Support

    Hi there,

    Not exactly sure what you are trying to do but I don’t believe so.

    The excerpt for GP and WP Show Posts is actually handled by WordPress’ core function.

    You can learn more about it here with lots of examples towards the bottom of the page:
    https://developer.wordpress.org/reference/functions/the_excerpt/

    You can check it out in action here:
    https://github.com/tomusborne/generatepress/blob/6933da4f9a85e183bcf8485836339043dfc4a650/content.php

    Hope this helps πŸ™‚

    #918332
    Andy

    Basically I want to put the excerpt inside an accordion/expander.

    #918372
    David
    Staff
    Customer Support

    Hi there,

    Instead of placing the excerpt inside a toggle we could do this:

    1. Create a new hook element
    1.1 Add this markup to create a toggle ‘button’:

    <span class="accordion-toggle">toggle</span>

    1.2 Select the after_entry_header hook
    1.3 Set you display rules to blog and archive

    2. Create a second hook for our our jQuery:

    <script type="text/javascript">
      jQuery(document).ready(function($) {
        $('.accordion-toggle').click(function(){
    
          //Expand or collapse this panel
          $(this).next().slideToggle('fast');
          
          //Hide the other panels
          $(".accordion-content").not($(this).next()).slideUp('fast');
          
          //Switch toggle
          $('.accordion-toggle.toggle-open').not(this).removeClass('toggle-open');
          $(this).toggleClass('toggle-open');
        });
      });
    </script>

    2.1 Select the WP_footer hook
    2.2 Set the display rules the same as first hook.

    3. Add this CSS to hide the Excerpt when page is first loaded:

    .entry-summary {
    	display: none;
    }

    You then just need to edit your original span for the toggle text / icon you want. When its open the toggle span will get the toggle-open class so you can style it differently.

    #918564
    Andy

    Thank you David this is working brilliantly on the Blog/Category Archive pages. Any way to get it working on WP Show Posts lists too?

    #918580
    David
    Staff
    Customer Support

    Awesome πŸ™‚
    so create another hook like the first one. This time select the Custom Hook in the hook list and in the field provided add: wpsp_after_title and set your display rules to cover any of the pages where WPSP is being used.

    #918596
    Andy

    ok I have the toggle displaying but it’s above the wp-show-posts-entry-summary html so doesn’t contain the excerpt.

    #918601
    David
    Staff
    Customer Support

    Here’s the main hooks you can add content to in WPSP:

    wpsp_before_wrapper
    wpsp_before_header
    wpsp_before_title
    wpsp_after_title
    wpsp_before_content
    wpsp_after_content
    wpsp_after_wrapper

    Maybe try the wpsp_before_content – if not i would need to see the site.

    #918607
    Andy

    Thanks David, I tried wpsp_before_content and it works but the toggle is open on page load, I’d want it closed.

    #918616
    Andy

    Silly me, all I had to do was add the WP Show Posts html to the display:none rule, .wp-show-posts-entry-summary.

    Thank you very much David it works really well.

    I’ve also learnt how to use the custom hooks feature which would seem to add even more power/customization options, as I believe it will allow you to use any hook from any plugin you have installed?.

    #918622
    David
    Staff
    Customer Support

    Aah my bad, yes the CSS needed updating
    That’s really cool – i like these sorts of ideas. May borrow that for another Site πŸ™‚

    Yes Custom Hooks any hook that is available for adding content can be used.

    #918899
    Andy

    Just thought I’d mention it doesn’t work when using Infinite Scroll. I had a feeling that would be the case as I was already using another hook below the title for another plugin and that doesn’t work with infinite scroll either. The plugin developer said it’s on his to-do list but isn’t an easy fix, so for the time being perhaps I will disable Infinite Scroll and just use normal pagination.

    #919260
    David
    Staff
    Customer Support

    Hmmm… i’ll take a look, thanks for reporting.

    #925104
    Andy

    Just wondering if you had any time to look into this yet?

    #925268
    David
    Staff
    Customer Support

    I think the issue is the jQuery isn’t being triggered in thee WP_Footer due to the infinite scroll. Nots sure though. Can you try moving it to the WP_head.

Viewing 15 posts - 1 through 15 (of 39 total)
  • You must be logged in to reply to this topic.