短码中的分页函数始终显示在顶部

时间:2015-03-22 作者:Hung PD

快捷码中的分页函数始终显示在顶部。请查看以下代码

/*-------------------------------------------------------------------------*/
/* Custom Pagination */
/*-------------------------------------------------------------------------*/

function suareztheme_pagination($pages = \'\', $range = 2){

    $showitems = ( $range * 2 ) + 1;  

    global $paged;
    if(empty($paged)) 
        $paged = 1;

    if($pages == \'\'){

        global $wp_query;
        $pages = $wp_query->max_num_pages;

        if(!$pages){

            $pages = 1;
        }
    }

    if( 1 != $pages ){

        $pagination_html .= \'<div class="pagination">\';

        if( $paged > 2 && $paged > $range + 1 && $showitems < $pages ){

            $pagination_html .= \'<a href="\' . get_pagenum_link( 1 ) . \'">&laquo;</a>\';

        }

        if( $paged > 1 && $showitems < $pages ){

            $pagination_html .= \'<a href="\' . get_pagenum_link( $paged - 1 ) . \'">&lsaquo;</a>\';

        }

        for ( $i = 1; $i <= $pages; $i++ ){

            if ( 1 != $pages && ( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )){

                if ( $paged == $i ){

                    $pagination_html .= \'<span class="current">\' . $i . \'</span>\';

                } else{

                    $pagination_html .= \'<a href="\' . get_pagenum_link( $i ). \'" class="inactive">\' . $i . \'</a>\';

                }
            }

        }

        if ( $paged < $pages && $showitems < $pages ){

            $pagination_html .= \'<a href="\' . get_pagenum_link( $paged + 1 ) . \'">&rsaquo;</a>\';

        }

        if ( $paged < $pages - 1 &&  $paged + $range - 1 < $pages && $showitems < $pages ){

            $pagination_html .= \'<a href="\' . get_pagenum_link( $pages ) . \'">&raquo;</a>\';

        }

        $pagination_html .= \'</div>\';

        return $pagination_html;
    }

}
然后我在shortcode函数中调用了它。

/*-------------------------------------------------------------------------*/
/* Grid Shortcode */
/*-------------------------------------------------------------------------*/

function RecentBlog($atts, $content = null) {
    extract(shortcode_atts(array(
        "comments" => \'true\',
        "date" => \'true\',
        "columns" => \'4\',
        "limit" => \'-1\',
        "title" => \'true\',
        "description" => \'true\',
        "cat_slug" => \'\',
        "post_type" => \'\',
        "excerpt_length" => \'15\',
        "readmore_text" => \'\',
        "pagination" => \'false\'
    ), $atts));

    global $post;

    $postformat = get_post_format();

    ....

    if ( get_query_var(\'paged\') ) {
        $paged = get_query_var(\'paged\');
    } elseif ( get_query_var(\'page\') ) {
        $paged = get_query_var(\'page\');
    } else {
        $paged = 1;
    }

    ......

    if (have_posts()) : while (have_posts()) : the_post();

        $postformat = get_post_format();
            if( $postformat == "" ) $postformat="standard";

        $protected = "";

        $portfoliogrid .= \'<div class="\' . $column_no . \' post grid-post post-\' . $postformat . \'">\';

            .....////

            $portfoliogrid .= \'<div class="summary-info">\';
                .......
            $portfoliogrid .=\'</div>\';

            // If either of title and description needs to be displayed.
            if ( $title == "true" || $description == "true" ) {

                $portfoliogrid .=\'<div class="work-details">\';
                ......
                $portfoliogrid .=\'</div>\';

            }

        $portfoliogrid .=\'</div>\';

    endwhile; endif;

    if ( $pagination == "true" ){

        if ( isset( $additional_loop ) ){

            echo suareztheme_pagination( $additional_loop->max_num_pages );

        } else {

            echo suareztheme_pagination();

        }

        if ( function_exists("suareztheme_pagination") ) {
        } else {

            next_posts_link(\'&laquo;&laquo; Older Posts\');
            previous_posts_link(\'Newer Posts &raquo;&raquo;\');

        }

    }
    wp_reset_query();
    return $portfoliogrid;
}

add_shortcode( "recentblog", "RecentBlog" );
上面的代码工作正常,但有一个问题,当它显示在特定页面中时,无论它位于何处,它总是显示在顶部。

1 个回复
最合适的回答,由SO网友:Pieter Goosen 整理而成

您的输出是预期的,但在我讨论解决方案和原因之前,您有几个问题

您可以使用query_posts 或者取消主全局查询,这是您永远不应该做的。赠送是你的循环(if (have_posts()) : while (have_posts()) : the_post();) 以及wp_reset_query();. 您应该使用WP_Query 并相应地调整分页功能。我最近编写了一个分页函数,它的功能与分页函数相同,但可用于自定义查询、主查询和静态首页。看看吧here

函数名(如果使用PSR 编码标准)应camelCase. Wordpress还没有使用PSR编码标准。Wordpress coding standards 声明函数名应全部为小写,单词之间用下划线分隔。

永远不要使用extract(). 此函数不可靠,如果失败,则很难调试。除此之外还有几个原因,extract() 不久前从核心完全移除。查看此票据:trac ticket #22400

  • global $post; 是不必要的,我看不到它在您的代码中的用法。而且$postformat = get_post_format(); 将返回未定义的变量通知。启用“调试”以查看调试错误

    您正在短代码中回显分页功能。短代码不应回显输出,应始终返回。回显的内容会产生意外的输出,就像您看到的是分页显示在帖子顶部的位置,而不是放置位置

    不要使用以下语法;endwhileendif. 虽然php是有效的,但很难调试,代码编辑器也不支持这种语法。而是用老式的卷发{} 它得到了代码编辑器的广泛支持,并且很容易调试

    编辑这里有一个或两个额外的问题

    • next_posts_link()previous_posts_link() 回应他们的输出,这在这里是不合适的。使用get_ 为函数添加前缀,并将其连接到稍后返回的yor变量

    • if ( isset( $additional_loop ) ){ 此检查是不必要的,因为$additional_loop 是始终存在的查询变量

      这是您的代码。我做了一些改变,其他的我刚刚评论过。有关更多详细信息,请参阅我在代码中的注释

      /*
       * Your function name is wrong, should be something like recent_blog
       */
      function RecentBlog($atts, $content = null) {
      
          /* 
           * This is the proper set up of attributes. 
           * Use your attributes as follow: $attributes[\'comments\']
           */
          $attributes = shortcode_atts(array(
              "comments"       => \'true\',
              "date"           => \'true\',
              "columns"        => \'4\',
              "limit"          => \'-1\',
              "title"          => \'true\',
              "description"    => \'true\',
              "cat_slug"       => \'\',
              "post_type"      => \'\',
              "excerpt_length" => \'15\',
              "readmore_text"  => \'\',
              "pagination"     => \'false\'
          ), $atts);
      
          // I don\'t know about this, does not make sense
          global $post;
      
          // This is a bug, will produce a undefined variable notice. Turn debug on
          $postformat = get_post_format();
      
          ....
      
          if ( get_query_var(\'paged\') ) {
              $paged = get_query_var(\'paged\');
          } elseif ( get_query_var(\'page\') ) {
              $paged = get_query_var(\'page\');
          } else {
              $paged = 1;
          }
      
          // Your query here is wrong. Use WP_Query. Something like below
      
          $args = array(
              \'posts_per_page\' => $attributes[\'limit\'],
              \'category_name\'  => $attributes[\'cat_slug\'],
              \'paged\'          => $paged,
              //etc
          );
          $additional_loop = new WP_Query( $args );
      
          /*
           * Give each condition its own line. Also use curlies
           * Do not use `query_posts`. Set your loop to your query variable which seems
           * to be $additional_loop
           */
          if ($additional_loop->have_posts()) { 
              while ($additional_loop->have_posts()) {
                  $additional_loop->the_post();
      
                  $postformat = get_post_format();
                      if( $postformat == "" ) $postformat="standard";
      
                  $protected = "";
      
                  $portfoliogrid .= \'<div class="\' . $column_no . \' post grid-post post-\' . $postformat . \'">\';
      
                      .....////
      
                      $portfoliogrid .= \'<div class="summary-info">\';
                          .......
                      $portfoliogrid .=\'</div>\';
      
                      /*
                       * Change all your attributes accordingly like I did below
                       * $title becomes $attributes[\'title\']
                       * $description becomes $attributes[\'description\']
                       */
                      // If either of title and description needs to be displayed.
                      if ( $attributes[\'title\'] == "true" || $attributes[\'description\'] == "true" ) {
      
                          $portfoliogrid .=\'<div class="work-details">\';
                          ......
                          $portfoliogrid .=\'</div>\';
      
                      }
      
                  $portfoliogrid .=\'</div>\';
      
              }
          }
      
          /*
           * Change attributes accordingly to new attribute syntax without extract()
           * $pagination becomes $attributes[\'pagination\']
           */
          if ( $attributes[\'pagination\'] == "true" ){
      
              /*
               * Do you really need this condition. $additional_loop will always exists as this is your
               * set query variable
               */
              if ( isset( $additional_loop ) ){
      
                  /*
                   * Do not echo your output. Concatenate it to your variable to be returned later
                   */
                  $portfoliogrid .= suareztheme_pagination( $additional_loop->max_num_pages );
      
              } else {
      
                  $portfoliogrid .= suareztheme_pagination();
      
              }
      
              /*
               * This seems all wrong. Don\'t know what is your intention here
               */
              if ( function_exists("suareztheme_pagination") ) {
      
              } else {
      
                  /*
                   * use the get_* prefix functions here and return them
                   */
                  $portfoliogrid .= get_next_posts_link(\'&laquo;&laquo; Older Posts\');
                  $portfoliogrid .= get_previous_posts_link(\'Newer Posts &raquo;&raquo;\');
      
              }
      
          }
          /*
           * This should be wp_reset_postdata(). wp_reset_query() is used with query_posts
           * which you should never use*/
          wp_reset_query();
          return $portfoliogrid;
      }
      /*
       * Change function call back name according to your new function name
       */
      add_shortcode( "recentblog", "RecentBlog" );
      
      编辑2下面是一个完整的短码示例。在粘贴代码之前,只需做几点注释

      我还没有测试代码。您不应该直接将其粘贴到活动站点中,首先在本地安装上测试它

      我已经对我所做的一切进行了评论,在测试代码之前,请比较我的代码和您的代码,确保您知道我所做的一切。完成后,如果愿意,可以删除注释

      一个非常重要的注意事项,comments_popup_link 回显其输出,该输出在短代码中不起作用。Wordpress中还没有返回其输出的替代函数。站点成员之一@Otto编写了一个自定义函数get_comments_popup_link (您可以在his personal site) 来克服这个问题。您需要在函数中复制并粘贴该函数。在添加短代码之前使用php。这是来自@Otto的函数

      /**
       * Modifies WordPress\'s built-in comments_popup_link() function to return a string instead of echo comment results
       */
      function get_comments_popup_link( $zero = false, $one = false, $more = false, $css_class = \'\', $none = false ) {
          global $wpcommentspopupfile, $wpcommentsjavascript;
      
          $id = get_the_ID();
      
          if ( false === $zero ) $zero = __( \'No Comments\' );
          if ( false === $one ) $one = __( \'1 Comment\' );
          if ( false === $more ) $more = __( \'% Comments\' );
          if ( false === $none ) $none = __( \'Comments Off\' );
      
          $number = get_comments_number( $id );
      
          $str = \'\';
      
          if ( 0 == $number && !comments_open() && !pings_open() ) {
              $str = \'<span\' . ((!empty($css_class)) ? \' class="\' . esc_attr( $css_class ) . \'"\' : \'\') . \'>\' . $none . \'</span>\';
              return $str;
          }
      
          if ( post_password_required() ) {
              $str = __(\'Enter your password to view comments.\');
              return $str;
          }
      
          $str = \'<a href="\';
          if ( $wpcommentsjavascript ) {
              if ( empty( $wpcommentspopupfile ) )
                  $home = home_url();
              else
                  $home = get_option(\'siteurl\');
              $str .= $home . \'/\' . $wpcommentspopupfile . \'?comments_popup=\' . $id;
              $str .= \'" onclick="wpopen(this.href); return false"\';
          } else { // if comments_popup_script() is not in the template, display simple comment link
              if ( 0 == $number )
                  $str .= get_permalink() . \'#respond\';
              else
                  $str .= get_comments_link();
              $str .= \'"\';
          }
      
          if ( !empty( $css_class ) ) {
              $str .= \' class="\'.$css_class.\'" \';
          }
          $title = the_title_attribute( array(\'echo\' => 0 ) );
      
          $str .= apply_filters( \'comments_popup_link_attributes\', \'\' );
      
          $str .= \' title="\' . esc_attr( sprintf( __(\'Comment on %s\'), $title ) ) . \'">\';
          $str .= get_comments_number_str( $zero, $one, $more );
          $str .= \'</a>\';
      
          return $str;
      }
      
      最后,这里是您的新短代码(希望可以使用)。我希望这能解决您的一些主要问题:-)

      function recent_blog_shortcode($atts, $content = null) {
      
          /*
           * Do not wrap booleans and integers in quotes. If they are wrapped in quotes
           * they are interpreted as string values. \'true\' !== true. First one is a string
           * while the second is a boolean
           *
           * Also, stick with single quotes (or double quotes), don\'t mix them, it is confusing
           * when it comes to debugging
           *
           * Do not use extract() as I have already explained
           */
          $attributes = shortcode_atts(array(
              \'comments\'       => true,
              \'date\'           => true,
              \'vote\'           => true,
              \'columns\'        => 4,
              \'limit\'          => -1,
              \'title\'          => true,
              \'description\'    => true,
              \'cat_slug\'       => \'\',
              \'post_type\'      => \'\',
              \'excerpt_length\' => 15,
              \'readmore_text\'  => \'\',
              \'pagination\'     => false
          ), $atts);
      
          /*
           * Stay out of the global scope. It is not very good practise.
           */
          global $post;
                 //$portfoliogrid, <-- Bad name for a global variable, too easy
                 //$column_no; <-- Bad name for a global variable, too easy
      
          /*
           * As precaution, check if $attributes[\'columns\'] is not empty. Also set the $columns variable from 
           * our attributes
           */
          $columns = $attributes[\'columns\'];
      
          /*
           * Sets the variables to make sure your two variables is not undefined (bug)
           * if $columns are empty
           */
          $column_no = \'\';
          $portfolioImage_type = \'\',
      
          if ( $columns ) {
      
              if ( $columns == 4 ) {
      
                  $column_no = \'col-md-3\';
                  $portfolioImage_type = \'gridblock-medium\';
      
              }
      
              if ( $columns == 3 ) {
      
                  $column_no = \'col-md-4\';
                  $portfolioImage_type = \'gridblock-large\';
      
              }
      
              if ( $columns == 2 ) {
      
                  $column_no = \'col-md-6\';
                  $portfolioImage_type = \'gridblock-large\';
      
              }
      
              if ( $columns == 1 ) {
      
                  $column_no = $columns;
                  $portfolioImage_type = \'gridblock-full\';
      
              }
      
          }
      
          /*
           * Again, stay with single quotes OR double quotes, going with single quotes
           */
          $postformats   = \'\';
          $terms         = \'\';
          $portfoliogrid = \'\';
      
          /*
           * Great job here 
           */
          if ( get_query_var(\'paged\') ) {
              $paged = get_query_var(\'paged\');
          } elseif ( get_query_var(\'page\') ) {
              $paged = get_query_var(\'page\');
          } else {
              $paged = 1;
          }
      
          /*
           * Change $post_type to our new attribute system, $attributes[\'post_type\']
           * For ease, just set the variable $post_type to the attribute
           */
          $post_type = $attributes[\'post_type\']; 
      
          if ( $post_type = \'\' ) {
      
              $type_explode = explode( \',\', $post_type );
              foreach ( $type_explode as $postformat ) {
                  $count++;
                  $postformat_slug = "post-format-" . $postformat;
                  $terms[] .= $postformat_slug;
              }
      
              /*
               * Never ever use query_posts. It breaks page functionalities, pagination
               * and the main query. Very bad function to use, please avoid it. Use WP_Query
               * instead. 
               *
               * Make your arguments conditional, not your query. Change our variables here to use the
               * new attribute system without extract()
               */
              $args = array(
                  \'category_name\'  => $attributes[\'cat_slug\'],
                  \'posts_per_page\' => $attributes[\'limit\'],
                  \'paged\'          => $paged,
                  \'tax_query\'      => array(
                      array(
                          \'taxonomy\' => \'post_format\',
                          \'field\'    => \'slug\',
                          \'terms\'    => $terms
                      )
                  )
              );
      
          } else {
      
              /*
               * Never ever use query_posts. It breaks page functionalities, pagination
               * and the main query. Very bad function to use, please avoid it. Use WP_Query
               * instead. 
               *
               * Make your arguments conditional, not your query. Change our variables here to use the
               * new attribute system without extract()
               */
              $args = array(
                  \'category_name\'  => $attributes[\'cat_slug\'],
                  \'paged\'          => $paged,
                  \'posts_per_page\' => $attributes[\'limit\'],
              );
      
          }
      
          /*
           * Create our query with WP_Query, very good practice
           */
          $q = new WP_Query( $args );
      
          $suareztheme_pagestyle = get_post_meta( $post->ID, \'pagestyle\', true );
      
          /*
           * Each condition on a new line, and use curlies
           * Set our loop to our custom query. VERY IMPORTANT
           */
          if ( $q->have_posts() ) {
              while ( $q->have_posts() ) {
      
                  $q->the_post();
      
                  $postformat = get_post_format();
                  if( $postformat == \'\' ) 
                      $postformat = \'standard\';
      
                  $protected = \'\';
      
                  $portfoliogrid .= \'<div class="\' . $column_no . \' post grid-post post-\' . $postformat . \'">\';
      
                      //if Password Required
                      /* 
                       * Where is MTHEME_PATH defined, this is a bug if MTHEME_PATH does not exists
                       */
                      if ( post_password_required() ) {
                          $protected = \' portfolio-protected\'; 
                          $iconclass = \'\';
                          $portfoliogrid .= \'<a class="grid-blank-element \'. $protected .\' gridblock-image-link gridblock-columns" title="\'. get_the_title() .\'" href="\'.get_permalink().\'" >\';
                          $portfoliogrid .= \'<span class="grid-blank-status"><i class="icon-lock icon-2x"></i></span>\';
                          $portfoliogrid .= \'<div class="portfolio-protected"><img src="\'. MTHEME_PATH .\'/images/icons/blank-grid.png" /></div>\';
                      } else {
                          // if ( ! has_post_thumbnail() ) {
                          //  $portfoliogrid .= \'<a class="grid-blank-element \'.$protected.\' gridblock-image-link gridblock-columns" title="\'.get_the_title().\'" href="\'.get_permalink().\'" >\';
                          //  $portfoliogrid .= \'<span class="grid-blank-status"><i class="\'.$postformat_icon.\' icon-2x"></i></span>\';
                          //  $portfoliogrid .= \'<div class="gridblock-protected"><img src="\'.MTHEME_PATH.\'/images/icons/blank-grid.png" /></div>\';
                          // }
      
                          if ( has_post_thumbnail() ) {
      
                              //Make sure it\'s not a slideshow
                              //Switch check for Linked Type
                              $portfoliogrid .= \'<a class="post-image" href="\' . get_permalink() . \'" rel="bookmark" title="\' . get_the_title(). \'">\';
      
                              // If it aint slideshow then display a background. Otherwise one is active in slideshow thumbnails.
                              // Custom Thumbnail
                              // Display Image
                              /*
                               * suareztheme_display_post_image is a custom function. You should first check
                               * if it exists, because if it does not, you will crash your site-content
                               */
                              if ( function_exists( \'suareztheme_display_post_image\' ) { 
                                  $portfoliogrid .= suareztheme_display_post_image (
                                      get_the_ID(),
                                      $have_image_url = \'\',
                                      $link = false,
                                      $type = $portfolioImage_type,
                                      $imagetitle = \'\',
                                      $class = \'preload-image displayed-image\'
                                  );
                              }
                          /*
                           * else if should be elseif. else if !== elseif
                           */
                          } elseif ( $postformat == \'gallery\' ){
      
                              /*
                               * the_post_format_gallery_content() is a custom function. You should first check
                               * if it exists, because if it does not, you will crash your site-content
                               */
                              if ( function_exists( \'the_post_format_gallery_content\' ) 
                                  $portfoliogrid .= the_post_format_gallery_content();
      
                          } else if ( $postformat == \'video\' || $postformat == \'audio\' ){
      
                              $embed_audio_code = get_post_meta($post->ID, \'audio_embed_code\', true);
                              $embed_video_code = get_post_meta($post->ID, \'video_embed_code\', true);
      
                              if ( $embed_audio_code ){
      
                                  $portfoliogrid .= \'<div>\' . $embed_audio_code . \'</div>\';
      
                              } else {
      
                                  $portfoliogrid .= \'<div>\' . $embed_video_code . \'</div>\';
      
                              }
      
                          } else if ( $postformat == "quote" ){
      
                              $portfoliogrid .= \'<div class="quote">\';
      
                                  $portfoliogrid .= \'<p class="quote-say">\' . get_post_meta($post->ID, \'meta_quote\', true) . \'</p>\';
      
                                  if ( $quote_author != \'\' ){
      
                                      $portfoliogrid .= \'<p class="quote-author">- \' . get_post_meta($post->ID, \'meta_quote_author\', true) . \'</p>\';
      
                                  }
      
                              $portfoliogrid .= \'</div>\';
      
                          } else {
      
                              $portfoliogrid .= \'<a class="\'. $protected .\' gridblock-image-link gridblock-columns" title="\'. get_the_title() .\'" href="\'. get_permalink() .\'" >\';
                              $portfoliogrid .= \'<div class="post-nothumbnail"></div>\';
      
                          } 
                      }
      
                      $portfoliogrid .= \'</a>\';
      
                      /*
                       * Don\'t wrap booleans in quotes as described earlier
                       * Also set our new attribute scheme
                       */
                      if ( $attribute[\'date\'] == true ){
      
                          $portfoliogrid .= \'<span class="date">\' . esc_html( get_the_date(\'F jS, Y\') ) . \'</span>\';
      
                      }
      
                      // If either of title and description needs to be displayed.
                      if ( $title == "true" ) {
      
                          $portfoliogrid .=\'<div class="entry-header">\';
      
                              $hreflink = esc_url( get_permalink() );
      
                              /*
                               * Don\'t wrap booleans in quotes as described earlier
                               * Also set our new attribute scheme
                               */
                              if ( $attribute[\'title\'] == true && $postformat == \'link\' ) {
      
                                  $portfoliogrid .=\'<h4><a href="\' . esc_url( get_post_meta( $post->ID, \'meta_link\', true ) ) . \'" rel="bookmark" title="\' . get_the_title() . \'">\'. get_the_title() .\'</a></h4>\'; 
      
                              } else {
      
                                  $portfoliogrid .=\'<h4><a href="\' . $hreflink . \'" rel="bookmark" title="\' . get_the_title() . \'">\'. get_the_title() .\'</a></h4>\'; 
      
                              }
      
                          $portfoliogrid .=\'</div>\';
      
                      }
      
                      /*
                       * Don\'t wrap booleans in quotes as described earlier
                       * Also set our new attribute scheme
                       */
                      if ( $attribute[\'description\'] == true ) {
      
                          /*
                           * Set our new attribute scheme
                           *
                           * suareztheme_excerpt_limit is a custom function. You should first check
                           * if it exists, because if it does not, you will crash your site-content
                           */
                          if ( function_exists( \'suareztheme_excerpt_limit\' ) { 
                              $summary_content = esc_attr( suareztheme_excerpt_limit($attribute[\'excerpt_length\']) );
      
                              $portfoliogrid .= \'<div class="entry-content"><p>\'. $summary_content .\'</p></div>\';
                          }
      
                      }   
      
                      /*
                       * Don\'t wrap booleans in quotes as described earlier
                       * Set our new attribute scheme
                       */
                      if (   $attribute[\'readmore_text\'] != \'\' 
                          || $attribute[\'comments\']      == true 
                          || $attribute[\'vote\']          == true 
                      ) {
      
                          $portfoliogrid .= \'<div class="entry-links">\';
                              $portfoliogrid .= \'<div class="entry-links-left">\';
                                  /*
                                   * dot_irecommendthis() is a custom function. You should first check
                                   * if it exists, because if it does not, you will crash your site-content
                                   *
                                   * Make sure dot_irecommendthis() returns its output, and not echo
                                   */
                                  if ( function_exists( \'dot_irecommendthis\' )  
                                      $portfoliogrid .= dot_irecommendthis();
      
                                  /*
                                   * comments_popup_link echos its output. There is no version that returns it output
                                   * Needs a workaround. See this article by Otto and use that function as a workaround
                                   * Link to article http://www.thescubageek.com/code/wordpress-code/add-get_comments_popup_link-to-wordpress/
                                   * Replace comments_popup_link with get_comments_popup_link and first check if the function
                                   * exists. Remember to copy the function from the link from Otto to functions.php
                                   */
                                  if ( function_exists( \'get_comments_popup_link\' )  
                                      $portfoliogrid .= \'<span class="entry-comments"><i class="fa fa-comments"></i>\' . get_comments_popup_link(\'Leave a Reply\', \'1\', \'%\') . \'</span>\';
      
                              $portfoliogrid .= \'</div>\';
      
                              $portfoliogrid .= \'<div class="entry-links-right">\';
                                  $portfoliogrid .= \'<a href="\' . $hreflink . \'" class="btn-readmore">\' . $attribute[\'readmore_text\'] . \' <i class="fa fa-chevron-right"></i></a>\';
                              $portfoliogrid .= \'</div>\';
                          $portfoliogrid .= \'</div>\';
      
                      }
      
                  $portfoliogrid .=\'</div>\';
      
              }
          }
      
          /*
           * Don\'t wrap booleans in quotes as described earlier
           * Set our new attribute scheme
           */
          if ( $attribute[\'pagination\'] == true ){
      
              $portfoliogrid .= \'<div class="col-md-12">\';
      
                  /* 
                   * Remember to set our maximum pages for the custom query*/
                  if ( function_exists( \'suareztheme_pagination\' ) ) {
      
                      $portfoliogrid .= suareztheme_pagination( $q->max_num_pages );
      
                  } else {
      
                      $portfoliogrid .= get_next_posts_link( \'&laquo;&laquo; Older Posts\', $q->max_num_pages );
                      $portfoliogrid .= get_previous_posts_link( \'Newer Posts &raquo;&raquo;\' );
      
                  }
      
              $portfoliogrid .= \'</div>\';
      
          }
      
          /*
           * Do not use wp_reset_query(), it is used with query_posts which you MUST NEVER use
           * Use wp_reset_postdata()
           */
          wp_reset_postdata();
      
          return $portfoliogrid;
      }
      
      add_shortcode( \'recentblog\', \'recent_blog_shortcode\' );
      

  • 结束

    相关推荐

    SHORTCODE_UNAUTOP()是否损坏?

    shortcode_unautop() 在里面/wp-includes/formatting.php 应该在文本块中找到短代码,并从中删除换行段落标记。在这个过程中,我一直对段落标记存在问题。以下是var_dump($pee), 我将其放在函数的最开头,即处理前的字符串:string(353) \"<p>[row wrap=\"true\"]</p> <p>[one_half]</p> <p>[text_block]Fusce