1. Improvement
2. Add functions.php code
//Get featured picture address function jsk_the_thumbnail_src() { global $post; If (get_post_meta ($post ->ID, 'thumbnail', true)) {//If there are thumbnails, thumbnails will be displayed $image = get_post_meta($post->ID, 'thumbnail', true); return $image; } else { If (has_post_thumbnail()) {//If there is a thumbnail, the thumbnail will be displayed $img_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "Full"); return $img_src[0]; } else { $content = $post->post_content; preg_match_all('/<img.*? (?: |\\t|\\r|\\n)? src=[\'"]?(.+?)[\'"]? (?:(?: |\\t|\\r|\\n)+.*?)?>/ sim', $content, $strResult, PREG_PATTERN_ORDER); $n = count($strResult[1]); if($n > 0){ return $strResult[1][0]; // If there is no thumbnail, take the first picture in the article as the thumbnail }else { $random = mt_rand(1, 9); return get_stylesheet_directory_uri().'/ img/random/'.$random.'.jpg'; //return get_template_directory_uri().'/ Img/thumbnail. png ';//If there is no picture in the article, set a random picture display } } } } //Short code in the article if(! function_exists('embed_posts')){ function embed_posts( $atts, $content = null ){ extract( shortcode_atts( array( 'ids' => '' ),$atts ) ); global $post; $content = ''; $postids = explode(',', $ids); $inset_posts = get_posts(array('post__in'=>$postids)); $category = get_the_category($ids); foreach ($inset_posts as $key => $post) { setup_postdata( $post ); $content .= '< div class="neilian">'; $content .= '< div class="fl">'; $content .= '< a target="_blank" href="'. get_permalink() .' " class="fl"><i class="fa fa-link fa-fw"></i>' . get_the_title() . '<span style="color:#FF5E52; ">' . get_the_subtitle() . '<span></a>'; $content .= '< p class="note"><span class="card-abstract">'. wp_trim_words( get_the_excerpt(), 100, '...' ) .'</span></p>'; $content .= '< P class="card controls"><span class="group data"><i>Time:</i>'. get_the_modified_date ('Y/n/j'). '</span><span class="group data"><i>Classification:</i><a target="_blank" href="'. get_category_link ($category [0] ->term_id). ' ">'. $category [0] ->cat_name.'</a></span><span class=" group data "><i>Popularity:</i>'. _get_post_views (false,' ',' ', false).'</span><span class=" group data "><i>Comments:</i>'. get_comments_number().'</span></p>'; $content .= '</ div>'; $content .= '< div class="fr">'; $content .= '< a target="_blank" href="'. get_permalink() .' "><img src='. jsk_the_thumbnail_src() .' class="neilian-thumb"></a>'; $content .= '</ div>'; $content .= '</ div>'; } wp_reset_postdata(); return $content; } } add_shortcode('jsk_embed_post', 'embed_posts');
3. Add shortcut button
//Add card inner link button function appthemes_add_embed_posts() { ?> <script type="text/javascript"> if ( typeof QTags != ' undefined' ) { QTags. addButton ('jsk_embed_post ',' In card link button ',' [jsk_embed_post ids=123] ',' '); } </script> <? php } add_action('admin_print_footer_scripts', 'appthemes_add_embed_posts' );
4. Add css style
.fl{float:left} .fr{float:right} .neilian { margin-bottom:25px; padding:10px; width:100%; overflow: hidden; border:1px dashed #d4d4d4; background:#fff; box-shadow:0 1px 0 rgba(0,0,0,.1); cursor:pointer; -webkit-transition:box-shadow 218ms; -moz-transition:box-shadow 218ms; -o-transition:box-shadow 218ms; transition:box-shadow 218ms; } .neilian:hover { box-shadow:0 1px 8px 1px rgba(0,0,0,.1); } .neilian .fl { width:72%; } .neilian .fr { padding:10px 5px; width:24%; } .neilian .fl a { display:block; margin-right:15px; padding:8px 5px; width:100%; color:#35a56b!important; text-decoration:none; font-size:16px; border:none; } .neilian .fl .note { margin:0 0 5px; padding-left:10px; font-size:14px; } .neilian .fl .card-controls { padding-left:10px; font-size:12px; } .neilian .fl .card-controls .group-data { float: left; margin-right: 10px; color: #999; } .neilian .card-controls .group-data i { margin-right: 5px; font-style: normal!important; } .neilian .card-controls .group-data a { font-size:12px; display:inline; margin-right:auto; padding:inherit; } .neilian .neilian-thumb{ width:170px; height:120px; } @media only screen and (max-width:700px) { .neilian .fl {width:100%;} .neilian .fr {display: none;} }
5. Add random pictures
$random = mt_rand(1, 9); return get_stylesheet_directory_uri().'/ img/random/'.$random.'.jpg';
6. Usage
【jsk_embed_post ids=123]
【jsk_embed_post ids=123,234]