Short Code Latest Post (HOW TO)
-
Hello,
I need to help in creating a short code, where i can do like a following image, and be able to select a specific category for the latest post. and also be able to set how many post to display.
http://i56.tinypic.com/2vt8hg2.jpg
also i want it to be something like that. i already have a shortcode that was included in the template i use ‘Prestige’ but it display the full post, with the image 600×270 and content and everything. i want it to look like the image i posted. one post with image and the tittle over the image and the date, and the rest of the post in a list like that.
-
here is what the shortcode looks like, can someone help me edit this, becuase ive been trying and the page wont load, if i edit the php file and save it.
# SHORTCODE: # dcs_recent_posts (display single news in shorter version) # PAREMAETERS: # NOTES: public function dcs_recent_posts($atts, $content=null, $code="") { global $post; global $more; // Declare global $more (before the loop). global $wp_query; global $post, $page, $numpages, $multipage, $more, $pagenow, $pages; $out = ''; $defatts = Array( 'count' => 3, 'image' => 'true', 'desc' => 'true', 'voting' => 'false', 'cat' => '', 'catex' => '', 'paged' => 'false' ); $atts = shortcode_atts($defatts, $atts); $att_count = $atts['count']; $att_image = $atts['image']; $att_desc = $atts['desc']; $att_voting = $atts['voting']; $att_cat = $atts['cat']; $att_catex = $atts['catex']; $att_paged = $atts['paged']; $paged = ($wp_query->query_vars['page']) ? $wp_query->query_vars['page'] : 1; $args=array('posts_per_page' => $att_count, 'post_type' => 'post'); if($att_paged == 'true') { $args['paged'] = $paged; } if($att_cat != '') { $args['category__in'] = explode(',', $att_cat); } if($att_catex != '') { $args['category__not_in'] = explode(',', $att_catex); } $new_query = new WP_Query($args); $max_page = $new_query->max_num_pages; if($new_query->have_posts()) { while($new_query->have_posts()) { $new_query->the_post(); $imagepath = get_post_meta($post->ID, 'post_image', true); $imagedesc = get_post_meta($post->ID, 'post_image_desc', true); $videopath = get_post_meta($post->ID, 'post_video', true); $disablevideo = get_post_meta($post->ID, 'post_disable_video', true); $postdesc = get_post_meta($post->ID, 'post_desc', true); $novoting = get_post_meta($post->ID, 'post_novoting', true); $more = 0; $month = get_the_time('n', $post->ID); $year = get_the_time('Y', $post->ID); $out .= ' <div class="blog-post">'; if($videopath != '' and $att_image == 'true' and $disablevideo == '') { $out .= '<div class="photo">'.do_shortcode($videopath).' '.($att_desc == 'true' ? $imagedesc : '').'</div>'; } else if($imagepath != '' and $att_image == 'true') { $out .= '<div class="photo"><a class="async-img image" href="'.get_permalink($post->ID).'" rel="'.$imagepath.'" ></a>'.($att_desc == 'true' ? $imagedesc : '').'</div>'; } else { $out .= '<div class="post-no-photo-spliter"></div>'; } $out .= '<div class="post-content"> <a href="'.get_comments_link($post->ID).'" class="comments">'.get_comments_number($post->ID).'</a> <div class="info"> <a class="date-left"></a><a href="'.get_month_link($year, $month).'" class="date">'.get_the_time('F j, Y').'</a><a class="date-right"></a> Posted by <a href="'.get_author_posts_url($post->post_author).'" class="author">'.get_the_author_meta('display_name', $post->post_author).'</a> in '; $catlist = wp_get_post_categories($post->ID); $count = count($catlist); for($i = 0; $i < $count; $i++) { if($i > 0) { $out .= ', '; } $cat = get_category($catlist[$i]); $out .= '<a href="'.get_category_link($catlist[$i]).'" >'.$cat->name.'</a>'; } $out .= '</div>'; $out .= '<h2><a href="'.get_permalink($post->ID).'">'.$post->post_title.'</a></h2>'; $old_page = $page; $page = 1; if($postdesc != '') { $out .= apply_filters('the_content', $postdesc); $out .= ' <a href="'.get_permalink($post->ID).'">Read more</a>'; } else { $out .= apply_filters('the_content', get_the_content('Read more')); } $page = $old_page; // post tags list $out .= '<div class="blog-post-bottom-wrapper">'; if(GetDCCPInterface()->getIGeneral()->showPostVoting() and $novoting == '' and $att_voting == 'true') { global $dcp_votingshortcodes; if(isset($dcp_votingshortcodes)) { $out .= $dcp_votingshortcodes->votePostStarsCreate($post->ID, GetDCCPInterface()->getIGeneral()->showVotingGlypsNum(), 'left', $post->post_type); } } $posttags = get_the_tags(); $count = 0; if($posttags !== false) { $count = count($posttags); } if($count > 0) { $out .= '<div class="blog-post-tags"> <span class="name">Tags:</span> '; $i = 0; foreach($posttags as $tag) { if($i > 0) { $out .= ', '; } $title = ''; if($tag->count == 1) { $title = 'One post'; } else { $title = $tag->count.' posts'; } $out .= '<a href="'.get_tag_link($tag->term_id).'" class="tag link-tip-bottom" title="'.$title.'">'.$tag->name.'</a>'; $i++; } $out .= '</div>'; } else { if(GetDCCPInterface()->getIGeneral()->showNoTags()) { $out .= '<div class="blog-post-tags"> There are no tags associated with this post. </div>'; } } $out .= '<div class="clear-both"></div></div>'; $out .= '</div> <!-- content --> </div> <!-- blog-post -->'; } // while } if($att_paged == 'true') { $out .= GetDCCPInterface()->getIGeneral()->renderSitePagination($paged, $max_page, false); } wp_reset_query(); return $out; } } // class ?>
The topic ‘Short Code Latest Post (HOW TO)’ is closed to new replies.