- This topic has 38 replies, 3 voices, and was last updated 4 years, 10 months ago by David.
-
AuthorPosts
-
June 2, 2019 at 4:08 pm #918051Andy
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.June 2, 2019 at 4:39 pm #918060LeoStaffCustomer SupportHi 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.phpHope this helps π
June 3, 2019 at 4:41 am #918332AndyBasically I want to put the excerpt inside an accordion/expander.
June 3, 2019 at 5:42 am #918372DavidStaffCustomer SupportHi 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 archive2. 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.June 3, 2019 at 6:51 am #918564AndyThank you David this is working brilliantly on the Blog/Category Archive pages. Any way to get it working on WP Show Posts lists too?
June 3, 2019 at 7:02 am #918580DavidStaffCustomer SupportAwesome π
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.June 3, 2019 at 7:25 am #918596Andyok I have the toggle displaying but it’s above the wp-show-posts-entry-summary html so doesn’t contain the excerpt.
June 3, 2019 at 7:32 am #918601DavidStaffCustomer SupportHere’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.June 3, 2019 at 7:41 am #918607AndyThanks David, I tried wpsp_before_content and it works but the toggle is open on page load, I’d want it closed.
June 3, 2019 at 7:45 am #918616AndySilly 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?.
June 3, 2019 at 7:52 am #918622DavidStaffCustomer SupportAah 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.
June 3, 2019 at 1:16 pm #918899AndyJust 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.
June 4, 2019 at 2:19 am #919260DavidStaffCustomer SupportHmmm… i’ll take a look, thanks for reporting.
June 10, 2019 at 10:19 am #925104AndyJust wondering if you had any time to look into this yet?
June 10, 2019 at 2:48 pm #925268DavidStaffCustomer SupportI 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.
-
AuthorPosts
- You must be logged in to reply to this topic.