Topic: Extract last post image (Snippet)

You need Blog plugin

 
<?php
  // Get post block
  $str = Blog::getPostsBlock();
  // Find inages of all posts
  preg_match_all('@<img.*src="([^"]*)"[^>/]*/?>@Ui', $str, $out);
  // Get first image of last post
  $img = $out[1][0];
  // Show image if you like add class or style
  echo '<img src=" '.$img.' ">';
 ?>

Get snippet

 {snippet get="name of snippet" }
..::: Moncho Varela ::::..   ..::: @Nakome ::::..   ..::: Github ::::..

nakome's Website

Re: Extract last post image (Snippet)

How to make the picture was a link to the last post?

Re: Extract last post image (Snippet)

@FullZero

You need to make it like this:

<?php
  // Get post block
  $str = Blog::getPostsBlock();
  $getmonstralinks = Blog::getPost();
  // Find inages of all posts and the posts
  preg_match_all('@<img.*src="([^"]*)"[^>/]*/?>@Ui', $str, $getmonstralinks, $out);
  // Get first image of last post and the post
  $img = $out[1][0];
  $getmonstralinks = $out[1][0];
  // Show image if you like add class or style
  echo '<a href=" '. getmonstralinks . ' "><img src=" '.$img.' "></a>';
 ?>

This should work for you! wink

http://monstracreative.com - themes, plugins and snippets for monstra cms

:: ATTENTION ::
Need help? Login at your account at: http://monstracreative.com/users/login. -> You have a excellent support center at our website! wink

wormsunited's Website