Comments showing up when not required
-
I am a newbie who is trying to make a new wordpress plugin.
This plugin creates a shortcode that will display the specified no. of posts from a specified category in a grid view along with the thumbnail images. And the i have generated the thumbs to be slighly bigger than the themes. Everything works fine except that i do not want the comments to be displayed for the gallery page. Without the shortcode the page is fine (with comments disabled) but with the shortcode, somehow the comments get enabled. Here is the php code (i know its not neat)//function to get the first image of the post as thumb function cat_post_thumb($size = 'post-thumbnail', $post_id = false){ global $post, $id; $post_id = (int)$post_id; if (!$post_id) $post_id = $id; $image = ''; if (has_post_thumbnail($post_id)) $image = get_the_post_thumbnail($post_id, $size); if(!$image): // get the 1st image $attachments = get_children(array('post_parent' => $post_id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID')); if($attachments): $attachment = array_shift($attachments); $image = wp_get_attachment_image($attachment->ID, $size); endif; endif; if($image && !get_post_meta($post->ID, 'asides', true)): echo '<a class="post-thumb size-'.$size.' aligncenter" href="'.get_permalink($post_id).'">'.$image.'</a>'; return true; endif; return false; } function mytheme_setup() { add_image_size('ansh', '250', '200', true ); //my custom thumb size } add_action( 'after_setup_theme', 'mytheme_setup' ); function catlist($atts, $content = null) { //function to list categories extract(shortcode_atts(array( "num" => '5', "cat" => '', "size" => 'thumbnail' ), $atts)); global $post; $sizeclass=$size; if(!((!strrchr($size, 'x'))&&(!strrchr($size, 'X')))){ if(strrchr($size, 'x')) $dchar='x'; else $dchar='X'; $size=explode($dchar,$size); } else if($size!='thumbnail' && $size!='medium' && $size!='large'){ $size='thumbnail'; $sizeclass=$size; } $myposts = get_posts('numberposts='.$num.'&order=DESC&orderby=post_date&category='.$cat); echo '<ul class="catlist">'."\n"; define('WP_USE_THEMES', false); foreach($myposts as $post) : setup_postdata($post); if($sizeclass==$size) echo '<li class="cat '.$sizeclass.'">'; else echo '<li class="cat" style="width:'.preg_replace( "|(\d+)|e", "$1+20", $size[0]).'px;height:'.preg_replace( "|(\d+)|e", "$1+10", $size[1]).'px;">'; $post_thumb =cat_post_thumb($size); echo '<p style="clear:both;"><a href="'.get_permalink().'">'.the_title("","",false).'</a></p></li>'."\n"; endforeach; echo '</ul> '; } add_shortcode("category", "catlist");
The shortcode is sumthing like
[category num=9 cat=4 size=250×250]it is working fine.. just that i do not want the comments on that page.
(its disabled/unchecked from the page options)Here is the link to the page to show you how it looks
https://shabdcreatives.com/portfolioand i have done some css styling over it
- The topic ‘Comments showing up when not required’ is closed to new replies.