WordPress.org

Forums

[resolved] I excerpt, you excerpt, he excerpts... but no excerpt available (11 posts)

  1. Goodvalley
    Member
    Posted 1 year ago #

    After a two-days crash course in designing a fantastic menu courtesy of designer and member of this forum DMBarber (thanks, man!), now I have a wonderful css menu for every post of my web.

    My theme Silverorchid shows a Slider, a Carrousel and five Featured Categories items that are amazing and show a snippet with an image and an excerpt for the last posts. Wonderful...

    The problem is that the css menu goes at the beginning of every post -and it has to be there-, so that all the excerpts now consist in the titles of that menu.

    The menu is the typical list in a div, and after doing a lot of research there seems not to be a good method of getting rid of the <div></div> tags AND what is between these tags, for just showing an excerpt of the text from the post.

    Can anybody help on that?

    Thanks in advance

  2. Dennis Barber
    Member
    Posted 1 year ago #

    Hello again. Do you create all the posts for your website?

    If yes: you can make your own excerpt when writing a new post. As of WordPress 3.1 this feature is auto-hidden. To enable to feature, on your 'Edit Post' page, at the top of the screen to the right side is a tab that reads: Screen Options. Click on that, then add a check mark to Excerpt. You can then write your own excerpt which will be displayed instead of the auto-excerpt created by WordPress when this field is empty.

    If no (or you have too many posts to manually edit to add an excerpt to using the above method): this may prove to be more difficult as the excerpts are inside the slider. And, are they used anywhere else?

  3. Goodvalley
    Member
    Posted 1 year ago #

    I'm ashamed for not knowing that Edit Post feature for the excerpts, but that being said,

    it doesn't work, as you can see if you go to my homepage http://www.drumscult.com

    I think it doesn't relate to the slider or the carroussel, as they always show just the first 60 characters of what's in the text of the actual post.

    In fact, before having the css menu, I had menus made from table with the Tablepress plugin. Those tables were called by a shortcode, so the plugin author told me to put a filter in functions.php (remember that code I had in styles.css that belonged to functions.php?). That filter made the excerpts to start at character number # of the post. As the tables shortcode were always the same lenght, I could give it a fixed number for it to skip that shortcode.

    Now it's a different situation as every menu has a different number of characters, so what I need is something that skips the <div>, </div> tags and the text between them. So nothing to do with the slider...

  4. Goodvalley
    Member
    Posted 1 year ago #

    Just to clarify, for stripping the Tables shortcode in the Featured Categories snippets of my homepage (see http://www.putrumputrum.com/en ) , I had to go to the php pages that generated them and add this:

    $content = strip_shortcodes( $content );

    which is a well-known WordPress function for removing shortcodes. Now, there should be a way to strip divs, classes or whatever...

  5. Goodvalley
    Member
    Posted 1 year ago #

    Then, there's this piece of code which I found in the Codex:

    function new_excerpt_more( $more ) {
    	return '[.....]';
    }
    add_filter('excerpt_more', 'new_excerpt_more');

    Can we play with that?

  6. Dennis Barber
    Member
    Posted 1 year ago #

    So... you can manually add excerpts to your posts!? Wonderful!

    I am still working on the full solution, but here is the solution for the slider:

    Write your excerpts manually using the method detailed above.

    Then...

    If you created a child theme (if you did not, I will cry, so do not tell me, and just follow these directions and skip the bits about creating and copying the file...), you will need to create a folder called 'includes' in your child theme folder and copy the file called 'slider.php' from the includes folder in the main theme folder to the new includes folder in your child theme directory. Then open the new copy of slider.php.

    [Read this first as it becomes clear when you see the final bit]
    Go to line 52 and copy $contents = get_the content(); to line 53 so you have that twice. Then wrap the first $contents = get_the content(); in a comment tag. On the uncommented line (line 53) change content() to excerpt(). Here is how it should look:

    <?php
    /*$content = get_the_content();*/
    $content = get_the_excerpt();
    $content = strip_tags($content);
    echo substr($content, 0, 150). '...';
    ?>

    Save the file and refresh your screen. IF this does not work, the above is much easier to reverse (delete the get_the_excerpt line and uncomment the original).

    This is a total hack, but it works...

  7. Dennis Barber
    Member
    Posted 1 year ago #

    which is a well-known WordPress function for removing shortcodes. Now, there should be a way to strip divs, classes or whatever...

    for this to work, we would need to identify the div, class, etc exactly or we would end up stripping ALL the divs, etc... Excerpts have not special identifier, so this would not work. We would have to add a class to the excerpt first to identify it, and if we did that we might as well just apply a filter to strip the first div (harder to do than say). But that is what I am actually working on doing...

  8. Goodvalley
    Member
    Posted 1 year ago #

    It works!

    But of course, only for the Slider, which means I have to go for the carroussel and the featuring categories, which are in the same folder and are coded similarly.

    Great work, DMBarber, really great...

    I'm going to check if everything works after the hack and post something here. It may be a hack but if it works...

    By the way, we are only dealing with one particular div (drummers-header) and one class (drummers-menu), can't that be passed through a filter function?

  9. Goodvalley
    Member
    Posted 1 year ago #

    Yeah, amazing!

    It definetly works in all levels, carousel and featured categories, same code applies to them.

    You're a genius!

  10. Dennis Barber
    Member
    Posted 1 year ago #

    Thanks, but I just switched the content that is retrieved.

  11. Goodvalley
    Member
    Posted 1 year ago #

    Yes, but that was a wise solution...

    Anyway, there has to be a good arrangement with a filter, maybe.

    But thanks again, DMBarber.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.