Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress最新头版文章(HTML)_Php_Wordpress - Fatal编程技术网

Php Wordpress最新头版文章(HTML)

Php Wordpress最新头版文章(HTML),php,wordpress,Php,Wordpress,我试图从我的网站的/blog目录在我的HTML/CSS首页上添加最近的3篇博客文章。到目前为止,它是可行的,但我遇到了一个问题;每当一篇文章的摘录限制很低时,它就不会显示“继续阅读”。我想知道我是否可以通过首页上的PHP改变摘录限制 以下是PHP的当前代码: <div class="ro-section ro-padding-top"> <h3 class="ro-hr-heading">Our Latest Blog Articles</h3>

我试图从我的网站的/blog目录在我的HTML/CSS首页上添加最近的3篇博客文章。到目前为止,它是可行的,但我遇到了一个问题;每当一篇文章的摘录限制很低时,它就不会显示“继续阅读”。我想知道我是否可以通过首页上的PHP改变摘录限制

以下是PHP的当前代码:

  <div class="ro-section ro-padding-top">
    <h3 class="ro-hr-heading">Our Latest Blog Articles</h3>
    <div class="container">
        <?php
          include('blog/wp-load.php');
          $args = array('showposts' => 6);
          $the_query = new WP_Query( $args );

          echo '<div class="row">';

            if( $the_query->have_posts() ): 
            while ( $the_query->have_posts()) : $the_query->the_post(); 

              echo '<div class="col-md-4">
              <h4 class="ro-service-item-4">'.get_the_title().'</h4>
              <a href="'.get_the_permalink().'">'.get_the_post_thumbnail().'</a>
              '.get_the_excerpt($limit).'</p></div>';

            endwhile; 
            endif; 

          echo '</div>';

          wp_reset_query(); 
        ?>
    </div>
  </div>

我们最新的博客文章

我通过谷歌搜索和在线阅读找到了答案。首先,您需要创建一个自定义函数:

      function get_excerpt(){
      $excerpt = get_the_content();
      $excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
      $excerpt = strip_shortcodes($excerpt);
      $excerpt = strip_tags($excerpt);
      $excerpt = substr($excerpt, 0, 100);
      $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
      $excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
      $excerpt = $excerpt.'...';
      return $excerpt;
      }
我还必须将“.get_extract($limit)”更改为“.get_extract()”,因为自定义函数已重命名

以下是所有代码:

  <div class="ro-section ro-padding-top">
<h3 class="ro-hr-heading">Our Latest Blog Articles</h3>
<div class="container">
    <?php
      include('blog/wp-load.php');
      $args = array('showposts' => 3);
      $the_query = new WP_Query( $args );

      function get_excerpt(){
      $excerpt = get_the_content();
      $excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
      $excerpt = strip_shortcodes($excerpt);
      $excerpt = strip_tags($excerpt);
      $excerpt = substr($excerpt, 0, 100);
      $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
      $excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
      $excerpt = $excerpt.'...';
      return $excerpt;
      }

      echo '<div class="row">';

        if( $the_query->have_posts() ): 
        while ( $the_query->have_posts()) : $the_query->the_post(); 

          echo '<div class="col-md-4">
          <h4 class="ro-service-item-4">'.get_the_title().'</h4>
          <a href="'.get_the_permalink().'">'.get_the_post_thumbnail().'</a>
          '.get_excerpt().'<br /><br />
          <a href="'.get_the_permalink().'"><button type="button" class="btn btn-read_more center-block">Read the article</button></a>
          </div>';

        endwhile; 
        endif; 

      echo '</div><br /><br /><br />';

      wp_reset_query(); 
    ?>
</div>

我们最新的博客文章

简短回答:是。长长的回答:你用谷歌搜索过这个吗?谷歌“WordPress WP_Query”,看看你找到了什么。@cale_b是的,我在谷歌上看过。我尝试添加一个wpdocs_custom_extract_length,但不确定如何完全实现它。仍在学习PHP。向我们展示您为自定义应用程序尝试的代码excerpt@FluffyKitten我想出来了。请看一下答案。谢谢你的鼓励。