Support » Plugin: Recently » First image of the recording

  • Resolved rianovost

    (@suryano11)


    Hello dear Hector! Your plug-ins have a great display feature for the first image of the recording, but the fact is that some recordings with miniatutours (thumbnal),And some without a miniatur thumbnail. Now, if you include the first 6 output in the settings of the plug-in, The rest of the recordings are displayed without a picture.
    question:
    Can’t you include both the thumbnal and the first image?

    For example, set the output thumbnail, and if not, then output the first picture from the
    For example, ask this code:`
    <?php
    /**
    *If you need a miniature to be displayed, and if it’s not, the first picture from the record, you need to insert the condition of the next kind
    */

    if ( has_post_thumbnail() ) {}
    else { ?>
    <img src=”<?php echo first_post_image() ?>” />
    <?php } ?> `

    The page I need help with: [log in to see the link]

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Héctor Cabrera

    (@hcabrera)

    Hi @suryano11,

    Can’t you include both the thumbnal and the first image?

    No, the plugin -as you already noticed- doesn’t provide such feature.

    You can easily add that functionality yourself though via Custom Content Tags.

    Here’s a real life example so you can see how this all works: ACF Integration. Follow the same logic and create a custom Content Tag (eg. {thumbnail_with_fallback}) that returns either a post thumbnail or the first image found on post content.

    Here’s a head start:

    /**
     * Parses custom content tags with Recently.
     *
     * @param  string  $html    The HTML markup from the plugin.
     * @param  integer $post_id The post/page ID.
     * @return string
     */
    function recently_my_custom_content_tags($html, $post_id){
    
        // Replace custom content tag {thumbnail_with_fallback} 
        // with a thumbnail
        if ( false !== strpos($html, '{thumbnail_with_fallback}') ) {
    
            if ( has_post_thumbnail($post_id) ) {
                $html = str_replace(
                    '{thumbnail_with_fallback}',
                    get_the_post_thumbnail($post_id, 'post-thumbnail'),
                    $html
                );
            }
            else {
                /**
                 * @TODO
                 *
                 * first_post_image() must be defined first
                 * as it's not a WordPress function.
                 *
                 * The function should return an <img> tag.
                 */
                $html = str_replace(
                    '{thumbnail_with_fallback}',
                    first_post_image(),
                    $html
                );
            }
        }
    
        return $html;
    }
    add_filter("recently_parse_custom_content_tags", "recently_my_custom_content_tags", 10, 2);

    Pay attention to the code though, it’s not a fully working one. You need to complete it so it does exactly what you want.

    Thread Starter rianovost

    (@suryano11)

    Thank you for the answer! But I have trouble: inserted your code, set in the widget your tag, now where the miniature is set, displays their huge size, but if it is possible to correct css, then where no miniature is set and the picture is just in the record, it just displays their link. Tried on the site rianovost.ru This is despite the fact that I turned off the display of thumbnails in the settings of the widget, or then shows two miniatures.
    Is there no option: “scan the image of the record, if you do not set a miniature”?
    For example, I have a plug-in slider (smooth slider), there just has such a feature, so all my slides with pictures. Please do something, it’s very important

    Plugin Author Héctor Cabrera

    (@hcabrera)

    But I have trouble: inserted your code, set in the widget your tag, now where the miniature is set, displays their huge size, but if it is possible to correct css, then where no miniature is set and the picture is just in the record, it just displays their link. Tried on the site rianovost.ru This is despite the fact that I turned off the display of thumbnails in the settings of the widget, or then shows two miniatures.

    Can’t help unless I see your code 😛

    Is there no option: “scan the image of the record, if you do not set a miniature”?

    As I pointed out above, no, there’s no such option.

    Plugin Author Héctor Cabrera

    (@hcabrera)

    Also, about the double thumbnails: remember to remove {thumb} from the HTML code or else you’ll get two pictures.

    Thread Starter rianovost

    (@suryano11)

    Can’t help unless I see your code 😛

    It’s the same code you wrote at the beginning, I copied it and inserted it into the function

    Thread Starter rianovost

    (@suryano11)

    Why instead of images only links?

    • This reply was modified 4 months ago by rianovost.
    Plugin Author Héctor Cabrera

    (@hcabrera)

    It’s the same code you wrote at the beginning, I copied it and inserted it into the function

    It seems that you somehow missed the last paragraph from my comment above. Here:

    Pay attention to the code though, it’s not a fully working one. You need to complete it so it does exactly what you want.

    If you copy & pasted the code without modifying it then you need to review it and make the following changes to it: set the right thumbnail size, code the fallback image function etc. Otherwise it won’t work as you expect it.

    Why instead of images only links?

    What do you mean?

    Thread Starter rianovost

    (@suryano11)

    What do you mean?

    Instead of the image shows a link to the image. The code unfortunately I could not change, every time gave errors

    Plugin Author Héctor Cabrera

    (@hcabrera)

    What errors exactly?

    Thread Starter rianovost

    (@suryano11)

    And I solved the smart question, – demolished the plugin and just inserted this code into the text widget

    <div id="pometkam"><h3></h3>
    <ul>
    <?php query_posts('category_name=lipetsk&showposts=9'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <li><div class="cell" ><a href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail(); ?>
    <?php
    	if ( has_post_thumbnail() ) {}
    else { ?>
    <img src="<?php echo first_post_image() ?>"  />
    <?php } ?> <?php the_title(); ?>
    </a></div> </li>
    <?php endwhile; ?>
    </ul></div>

    Now I have anywhere displayed the latest news from any column without any plugin and most importantly that they are in any case with images, either thumbnail or image recording

    Thread Starter rianovost

    (@suryano11)

    You should add to the plug-in the possibility of either a miniature or a recording image without any bother. After all, not everyone has the time and opportunity to dig through the codes and long correspond with the authors of plug-ins, who instead of solve the issue send non-working codes

Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.