Comments showing up when not required (2 posts)

  1. Anshul
    Posted 5 years ago #

    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'));
          $attachment = array_shift($attachments);
          $image = wp_get_attachment_image($attachment->ID, $size);
      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;
      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
                    "num" => '5',
                    "cat" => '',
    		"size" => 'thumbnail'
            ), $atts));
            global $post;
    	if(!((!strrchr($size, 'x'))&&(!strrchr($size, 'X')))){
    		if(strrchr($size, 'x')) $dchar='x';
    		else $dchar='X';
    	else if($size!='thumbnail' && $size!='medium' && $size!='large'){
    	$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) :
    		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";
            echo '</ul> ';
    add_shortcode("category", "catlist");

    The shortcode is sumthing like
    [category num=9 cat=4 size=250x250]

    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

    and i have done some css styling over it

  2. Anshul
    Posted 5 years ago #

    i can really use some help here guys.. :S

Topic Closed

This topic has been closed to new replies.

About this Topic