Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Any Short code Availble for Get Post List With Thumbnail Plugin? or else how to Create Short code for this Particular plugin? Thank u in Advance.

share|improve this question
    
Get Post List With Thumbnail Plugin is a widget which has option panel its not a quick fix to make it a shortcode. –  Bainternet Jun 1 '11 at 11:50
    
absolutely you are correct Bainternet,but i want to develop this plugin by Adding Shortcode.We need to Use this Plugin Under Any Post or Any Page means we need to create shortcode..It Would be Great.Isn't? –  Ramkumar Jun 1 '11 at 12:04

3 Answers 3

up vote 1 down vote accepted

here is a quick crack at making it a shortcode paste this code in your theme's functions.php file:

add_shortcode('gplt','getPostListThumbs_shortcode');
function getPostListThumbs_shortcode($atts, $content = null){

    extract(shortcode_atts(array(
        'orient' => 'v',
        'imgo' => false,
        'ttgo' => false,
        'dtgo' => false,
        'dtfrm' => 1,
        'categ' => '',
        'postnr' => 20,
        'linn' => 3,
        'tbwid' => 40,
        'tbhig' => 40       
    ), $atts));
    $orient = gtpartrat($orient,'v');
    $imgo = gtpartrat($imgo,false);
    $ttgo = gtpartrat($ttgo,false);
    $dtgo = gtpartrat($dtgo,false);
    $dtfrm = gtpartrat($dtfrm,1);
    $categ = gtpartrat($categ,'');
    $postnr = gtpartrat($postnr,20);
    $linn = gtpartrat($linn,3);
    $tbwid = gtpartrat($tbwid,40);
    $tbhig = gtpartrat($tbhig,40);

    $htmlcod = "<table id='div_postlist' width='".$divwid."' cellpadding='4' cellspacing='4'>"."\n";
    $htmlcod .= "<tr>"."\n";
    //
    if (have_posts()) :
        global $post;

        if($categ!=''){
            $strquery = "numberposts=".$postnr."&category_name=". $categ;
        }
        else{
              $strquery =  "numberposts=".$postnr;
        }

        $myposts=get_posts($strquery);

        $ctxtr = 0;
        switch($dtfrm){
            case 1:
                $dtdis = 'd/m/y';
            break;
            case 2:
                $dtdis = 'm/d/y';
            break;
        }
        if($myposts):

        foreach($myposts as $post) :

                    $args = array(
                        'post_type' => 'attachment',
                        'numberposts' => -1,
                        'post_status' => null,
                        'post_parent' => $post->ID
                    );
                    $attachments = get_posts($args);


                    $imgsrc = "";
                    if ($attachments):

                        foreach ($attachments as $attachment) {

                            $imgsrc = wp_get_attachment_image($attachment->ID, array($tbwid,$tbhig), $icon = false);
                            break;
                        }
                    endif;

                    if($orient=="v"){     
                            if($ctxtr == 0){
                                $htmlcod .= "<tr>"."\n";
                            } 
                            $ctxtr = $ctxtr + 1;

                                $htmlcod .= "<td valign='top'>"."\n";
                            if($imgsrc!=""):                           
                                $htmlcod .= "<a href='". get_permalink() ."' title='". get_the_title() ."'>"."\n";
                                $htmlcod .= $imgsrc;
                                $htmlcod .= "</a>"."\n";                           
                            endif;
                                $htmlcod .= "</td>"."\n";

                            if(!$imgo){           
                                $htmlcod .= "<td valign='top'>"."\n";
                                if($dtgo):
                                $htmlcod .= "<p>".get_the_time($dtdis)."</p>";
                                endif;
                                if($ttgo):
                                $htmlcod .= "<a href='". get_permalink()."' title='". get_the_title() ."'>";
                                $htmlcod .= get_the_title();
                                $htmlcod .= "</a>"."\n";
                                endif;
                                $htmlcod .= "</td>"."\n";
                            }
                            $htmlcod .= "</tr><tr>"."\n";  
                    }
                    else{

                            if($ctxtr == 0){
                                $htmlcod .= "<tr>"."\n";
                            }      
                            $ctxtr = $ctxtr + 1;                      
                            $htmlcod .= "<td valign='top'>"."\n";
                            $htmlcod .= "<table cellpadding='3' cellspacing='3' border='0' width='100%'>"."\n";

                                $htmlcod .= "<tr>"."\n";
                                $htmlcod .= "<td valign='top'>"."\n";
                            if($imgsrc!=""):                           
                                $htmlcod .= "<a href='". get_permalink() ."' title='". get_the_title() ."'>"."\n";
                                $htmlcod .= $imgsrc;
                                $htmlcod .= "</a>"."\n";    
                                $htmlcod .= "</td>"."\n";                       
                            endif;

                            if(!$imgo){  
                                $htmlcod .= "<td valign='top'>"."\n";             
                                if($dtgo):
                                $htmlcod .= "<p>".get_the_time($dtdis)."</p>";
                                endif;
                                if($ttgo):
                                $htmlcod .= "<a href='". get_permalink()."' title='". get_the_title() ."'>";
                                $htmlcod .= get_the_title();
                                $htmlcod .= "</a>"."\n";
                                endif;      
                                $htmlcod .= "</td>"."\n";                         
                            }
                            $htmlcod .= "</td>"."\n";
                            $htmlcod .= "</tr>"."\n";
                            $htmlcod .= "</table>"."\n";
                            $htmlcod .= "</td>"."\n";
                            if($ctxtr == $linn){
                                $htmlcod .= "</tr>"."\n";
                                $ctxtr = 0;
                            }
                    }
        endforeach;
        else:
            $htmlcod = "<tr>"."\n";
            $htmlcod = "<td>"."\n";
            $htmlcod .= "No registers found."."\n";
            $htmlcod .= "</td>"."\n";
            $htmlcod .= "</tr>"."\n";
        endif;
    endif;
        $htmlcod .= "</table>";
    return $htmlcod;
}

Usage:

simply call the shortcode [gplt parametes] from any post or a page

parameters:

  • Orientation: orient="v" // v = Vertical , h = Horizontal default 'v'
  • Display only images: imgo="false" // true, false default 'false'
  • Display post title: ttgo="false" // true, false default 'false'
  • Display post date: dtgo="false" // true, false default 'false'
  • Date Format: dtfrm="1" // 1 - d/m/y , 2 - m/d/y default '1'
  • Category Name: categ='' // leave out or blank for all categories default ''
  • Number of Posts: postnr="20" //default=20
  • Number of registers per line: linn="3" //default=3 only for horizontal orientation
  • Thumbnails Width: tbwid="40" //default = 40
  • Thumbnails Height: tbhig="40" //default = 40
share|improve this answer
    
Thank you Very Much Bainternet.Really Amazing performance done by you.But Still Am not Getting This Plugin in My Page.I added Your code in functions.php and Activate the Plugin.Then i Create a Short code like [gplt orient="v",imgo="true",ttgo="false",dtgo="false",categ='',postnr="100",tbwid="13‌​0",tbhig="75"] under a New Page.where i had done Mistake? –  Ramkumar Jun 1 '11 at 14:02
    
Replace the comma with spaces between each parameter –  Bainternet Jun 1 '11 at 14:57
    
am changed my code to [gplt orient="v" imgo="true" ttgo="false" dtgo="false" categ='' postnr="100" tbwid="130" tbhig="75"].but still it's not working.i got an Empty Page only & No Error's are Shown. –  Ramkumar Jun 2 '11 at 4:19
    
What are the errors –  Bainternet Jun 2 '11 at 4:47
    
please Solve My Problem.may you help me @Bainternet? –  Ramkumar Jun 2 '11 at 7:12

I've developed a new version for Get Post List With Thumbnails 4.0.0 and now it's possible to use shortcodes.

share|improve this answer
    
Wow,Great work.Welcome to wordpress.stackexchange.com. i give it works in wordpress.org. Try to add useful plugin like this.:) keep rocking.. –  Ramkumar Sep 9 '11 at 5:04
    //Shortcode for Get Recent Post Thumbnail
add_shortcode('gplt','getPostListThumbs_shortcode');

function getPostListThumbs_shortcode($atts, $content = null){

extract(shortcode_atts(array(
    'orient' => 'v',
    'imgo' => true,
    'ttgo' => true,
    'dtgo' => false,
    'dtfrm' => 1,
    'categ' => '',
    'postnr' => 500,
    'linn' => 3,
    'tbwid' => 175,
    'tbhig' => 100       
), $atts));
$orient = gtpartrat($orient,'v');
$imgo = gtpartrat($imgo,false);
$ttgo = gtpartrat($ttgo,false);
$dtgo = gtpartrat($dtgo,false);
$dtfrm = gtpartrat($dtfrm,1);
$categ = gtpartrat($categ,'');
$postnr = gtpartrat($postnr,500);
$linn = gtpartrat($linn,3);
$tbwid = gtpartrat($tbwid,175);
$tbhig = gtpartrat($tbhig,100);

$htmlcod = "<table id='div_postlist' width='".$divwid."' cellpadding='4' cellspacing='4'>"."\n";
$htmlcod .= "<tr>"."\n";
//

// if (have_posts()) : global $post;

    if($categ!=''){
        $strquery = "numberposts=".$postnr."&category_name=". $categ;
    }
    else{
          $strquery =  "numberposts=".$postnr;
    }

    $myposts=get_posts($strquery);

    $ctxtr = 0;
    switch($dtfrm){
        case 1:
            $dtdis = 'd/m/y';
        break;
        case 2:
            $dtdis = 'm/d/y';
        break;
    }
    if($myposts):

    foreach($myposts as $post) :

                $args = array(
                    'post_type' => 'attachment',
                    'numberposts' => -1,
                    'post_status' => null,
                    'post_parent' => $post->ID
                );
                $attachments = get_posts($args);


                $imgsrc = "";
                if ($attachments):

                    foreach ($attachments as $attachment) {

                        $imgsrc = wp_get_attachment_image($attachment->ID, array($tbwid,$tbhig), $icon = false);
                        break;
                    }
                endif;

                if($orient=="v"){     
                        if($ctxtr == 0){
                            $htmlcod .= "<tr>"."\n";
                        } 
                        $ctxtr = $ctxtr + 1;

                            $htmlcod .= "<td valign='top'>"."\n";
                        if($imgsrc!=""):                           
                            $htmlcod .= "<a href='". get_permalink() ."' title='". get_the_title() ."'>"."\n";
                            $htmlcod .= $imgsrc;
                            $htmlcod .= "</a>"."\n";                           
                        endif;
                            $htmlcod .= "</td>"."\n";

                        if(!$imgo){           
                            $htmlcod .= "<td valign='top'>"."\n";
                            if($dtgo):
                            $htmlcod .= "<p>".get_the_time($dtdis)."</p>";
                            endif;
                            if($ttgo):
                            $htmlcod .= "<a href='". get_permalink()."' title='". get_the_title() ."'>";
                            $htmlcod .= get_the_title();
                            $htmlcod .= "</a>"."\n";
                            endif;
                            $htmlcod .= "</td>"."\n";
                        }
                        $htmlcod .= "</tr><tr>"."\n";  
                }
                else{

                        if($ctxtr == 0){
                            $htmlcod .= "<tr>"."\n";
                        }      
                        $ctxtr = $ctxtr + 1;                      
                        $htmlcod .= "<td valign='top'>"."\n";
                        $htmlcod .= "<table cellpadding='3' cellspacing='3' border='0' width='100%'>"."\n";

                            $htmlcod .= "<tr>"."\n";
                            $htmlcod .= "<td valign='top'>"."\n";
                        if($imgsrc!=""):                           
                            $htmlcod .= "<a href='". get_permalink() ."' title='". get_the_title() ."'>"."\n";
                            $htmlcod .= $imgsrc;
                            $htmlcod .= "</a>"."\n";    
                            $htmlcod .= "</td>"."\n";                       
                        endif;

                        if(!$imgo){  
                            $htmlcod .= "<td valign='top'>"."\n";             
                            if($dtgo):
                            $htmlcod .= "<p>".get_the_time($dtdis)."</p>";
                            endif;
                            if($ttgo):
                            $htmlcod .= "<a href='". get_permalink()."' title='". get_the_title() ."'>";
                            $htmlcod .= get_the_title();
                            $htmlcod .= "</a>"."\n";
                            endif;      
                            $htmlcod .= "</td>"."\n";                         
                        }
                        $htmlcod .= "</td>"."\n";
                        $htmlcod .= "</tr>"."\n";
                        $htmlcod .= "</table>"."\n";
                        $htmlcod .= "</td>"."\n";
                        if($ctxtr == $linn){
                            $htmlcod .= "</tr>"."\n";
                            $ctxtr = 0;
                        }
                }
    endforeach;
    else:
        $htmlcod = "<tr>"."\n";
        $htmlcod = "<td>"."\n";
        $htmlcod .= "No registers found."."\n";
        $htmlcod .= "</td>"."\n";
        $htmlcod .= "</tr>"."\n";
    endif;
// endif;
    $htmlcod .= "</table>";
return $htmlcod;

} i Found the bug in this line 'if (have_posts()) :' .We Need to make Comment Lines. 1.//if (have_posts()) : 2. // endif; Now It's Working Fine.Hurrahhhhh.Thanks Bainternet :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.