WordPress.org

Ready to get started?Download WordPress

Forums

Multiple content blocks
[resolved] tag not working (13 posts)

  1. Socke
    Member
    Posted 6 months ago #

    I'm using the <?php global $more; $more = 0; ?> "hack" to make the more-tag work on pages. It works well in the normal content, but not in the mcb-content.

    Any idea?

    http://wordpress.org/plugins/multiple-content-blocks/

  2. Harold Angenent
    Member
    Plugin Author

    Posted 6 months ago #

    Actually, no. MCB uses the same filters as the normal content. The content seems to be removing the rest on its own.

    That means you should use code to show part of the content block. Maybe you can take a look at https://core.trac.wordpress.org/browser/tags/3.8.1/src/wp-includes/post-template.php#L180?

  3. Socke
    Member
    Posted 6 months ago #

    Thanks for your help! But how can i insert some code in MCB? "the more on pages hack" is inserted in the template in the loop right under "<?php while( have_posts() ) : the_post(); ?>", so i guess there should be some kind of template for MCB where i could insert that hack too?

    by reading the linked code, i guess i understand most of that stuff, but we cannot change that, as it's the wp-source, right?

  4. Harold Angenent
    Member
    Plugin Author

    Posted 6 months ago #

    No, but this is how the WordPress the_content function works. If you want the same thing for a custom block, you should replicate that code.

    So that 'hack' won't work on MCB, since it doesn't replicate the the_content function by default.

    If you want to show part of a content block, you could use the function wp_trim_words: http://codex.wordpress.org/Function_Reference/wp_trim_words

  5. Socke
    Member
    Posted 6 months ago #

    ok, thanks a lot! Where should i add some code to prevent it from beeing overwrtten with a future update?

  6. Harold Angenent
    Member
    Plugin Author

    Posted 6 months ago #

    There is no need to edit the plugin, instead of the_block( 'Blockname' ); you can try something like echo wp_trim_words( get_the_block( 'Blockname'), 40 );.

    If you put it in your template, a plugin update won't overwrite it. Good luck!

  7. Socke
    Member
    Posted 6 months ago #

    thanks a lot, i'll try that and see what happens.

  8. Socke
    Member
    Posted 6 months ago #

    sorry for the delay, i ran out of time...
    So now i tried this:

    <?php echo wp_trim_words( get_the_block('unterer_block_1'), 40 ); ?>

    well, it works partially... It cuts the text after 40 word, but it also cuts all html-formats like <h3> and <img> and finally there's no read-more-link at the end of the stripped text. 3 dots and nothing more.

    So i guess i'm stuck again...

    edit:
    if i try <?php the_content( get_the_block('unterer_block_2') ); ?> the text won't be cut, but the whole text becomes the read-more-link, which is of course not working. But at least the html-formats won't be cut.

    So i guess, we are on the right way, but there's still some way to go...

  9. Harold Angenent
    Member
    Plugin Author

    Posted 6 months ago #

    Socke,

    How about <?php echo strstr( get_the_block('unterer_block_2'), '<!--more-->', true ); ?>?

    http://nl1.php.net/strstr

  10. Socke
    Member
    Posted 6 months ago #

    Warning: Wrong parameter count for strstr() in /WWWROOT/227712/htdocs/wp-content/themes/responsive-child/Inhalt_Sidebar_Block_unten.php on line 75

  11. Harold Angenent
    Member
    Plugin Author

    Posted 6 months ago #

    The last parameter was added from PHP 5.3. Maybe you have a lower version.

    I'm glad to help you when there's a problem / bug with my plugin, but this is just one of the implementations you could do with it. In my opinion, this is more PHP support.

    I think I've given you a lot of pointers for where to look, but I'm afraid I don't have time to answer all PHP support questions. Good luck!

  12. Socke
    Member
    Posted 6 months ago #

    Ok, thanks a lot. If i get it running, i'll post it here. If not, i'm dead :-D

  13. Socke
    Member
    Posted 6 months ago #

    I updated to 5.3 and the error is gone, the text is cut at the right place, all html-tags are working, only the read-more-link is missing.

Reply

You must log in to post.

About this Plugin

About this Topic

Tags