WordPress.org

Ready to get started?Download WordPress

Forums

Manual Related Posts
[resolved] Replace thumb with first image post (7 posts)

  1. flandreau
    Member
    Posted 1 year ago #

    Hi Julio,

    First thanks for the quick update of this plugin it works perfectly for now.

    I have a question. Perhaps this is already possible but I can't figure out how it is possible. In my blog all post are starting with an image. testing different "related posts" plugins I saw for example the with SEO ALRP that related posts come with this first image. With you plugin I just have the wordpress thumb. Is it possible to make in sort that when I choose the display with thumb I have my first image post coming instead of the wp thumb?

    Thanks in advance

    François

    http://wordpress.org/extend/plugins/baw-manual-related-posts/

  2. Julio Potier
    Member
    Plugin Author

    Posted 1 year ago #

    Hello

    yes you can use the "bawmrp_no_thumb" filter, like this:

    function catch_my_first_image( $image, $post_id )
    {
      $_post = get_post( $post_id );
      if( !$_post ) return $image;
      $image = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $_post->post_content, $matches );
      if( isset( $matches[1][0] ) )
        $image = $matches[1][0];
      return $image;
    }
    
    add_filter( 'bawmrp_no_thumb', 'my_own_bawmrp_thumb' );
    function my_own_bawmrp_thumb( $thumb, $post_id )
    {
        return catch_my_first_image( $thumb, $post_id );
    }

    You can also use the "bawmrp_thumb_size" to change the thumb zize, like this:
    add_filter( 'bawmrp_no_thumb', 'my_own_bawmrp_thumb' );

    function my_own_bawmrp_thumb_size( $sizes )
    {
        return array( '64', '64' ); // only 64px
    }

    ps : not tested, just coded here.

  3. flandreau
    Member
    Posted 1 year ago #

    Many Thanks Julio,

    last question around this :). I'm not really a strong wordpress user so i'd like to know where I must put this code. Is it in the function.php, a plugin file, or in any other place?

    François

  4. Julio Potier
    Member
    Plugin Author

    Posted 1 year ago #

    Sorry, copy/paste this in your functions.php from your activated theme folder.

  5. flandreau
    Member
    Posted 1 year ago #

    ok thank you. I think I must have a problem with my theme because this is not working. I'm using a wootheme typebased and for what i have seen in another module perhaps I miss some thumb functionnalities

    François

  6. flandreau
    Member
    Posted 1 year ago #

    ok I think I have no problem with my theme at the end. I rmeoved plugin cach and now images are broken. When I inspect element I see this:
    <img src="0" height="100" width="100"> where the image url is replaced by '0' perhaps there is a problem in the code you just made ?

  7. Julio Potier
    Member
    Plugin Author

    Posted 1 year ago #

    my bad this is:

    add_filter( 'bawmrp_no_thumb', 'my_own_bawmrp_thumb', 10, 2 );

    and NOT

    add_filter( 'bawmrp_no_thumb', 'my_own_bawmrp_thumb' );

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.