按类别分类的相关帖子引发内部服务器错误

时间:2014-11-07 作者:Sanjay Nakate

我正在使用wordpress 4.1中的论文,我试图使用下面的功能按类别显示相关帖子,但当我转到帖子详细信息页面时,它会引发内部服务器错误。我在另一个网站上使用了相同的代码,该网站上的代码运行良好,两个网站上的每个代码单词都是相同的。我在这里被绊住了。我在php中增加了wordpress内存限制。ini文件内存限制,但也不起任何作用。所以请引导我使用下面的代码显示相关帖子。我想知道我在另外两个网站上使用的代码是什么,这两个网站都有论文主题,而且效果很好。

<?php

    function related_posts() {
      if ( is_single() ) {
       global $post;
         $categories = get_the_category();
          foreach ($categories as $category)
           {
      ?>
 <div class="relatedpostAdd">
 <h3 style="margin:5px 0 ">More From <?php echo $category->name; ?></h3>
 <ul>
 <?php
       $posts = get_posts(\'numberposts=4&category=\'. $category->term_id);
         foreach($posts as $post)
          {
       ?>
 <li>
     <div class="images_releted">
       <a class="post_thumbnail" href="<? the_permalink()?>" rel="bookmark" title="<?php   
           the_title(); ?>"><?php echo the_post_thumbnail(\'thumbnail\') ?>
          </a>
     </div>
    <a class="post_thumbnail_link" href="<? the_permalink()?>" rel="bookmark" 
    title="<?php the_title(); ?>"><?php short_title(); ?></a>               
 </li>
        <?php } ?>
                  </ul>
 </div>
    <?php } ?>
<?php
     $orig_post = $post;
       global $post;
        $tags = wp_get_post_tags($post->ID);
        if ($tags) {
        $tag_ids = array();
        foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
           $args=array(
                       \'tag__in\' => $tag_ids,
                       \'post__not_in\' => array($post->ID),
                       \'posts_per_page\'=>4,
                       \'caller_get_posts\'=>1,
                       \'orderby\'=>\'rand\'
                                          );          
        $my_query = new wp_query( $args );
          if( $my_query->have_posts() ) 
          {
           echo \'<div class="relatedpostAdd">
                 <div id="related_posts1" class="reviews clear">
                 <h3 style="margin:5px 0 ">Related Posts</h3>
                 <ul>\';
         while( $my_query->have_posts() ) 
         {
            $my_query->the_post(); 
        ?>
 <li>
  <div class="images_releted">
     <a class="post_thumbnail" href="<? the_permalink()?>" rel="bookmark" 
     title="<?php the_title(); ?>"><?php echo the_post_thumbnail(\'thumbnail\') ?>
     </a>
  </div>
    <a class="post_thumbnail_link" href="<? the_permalink()?>" rel="bookmark" 
     title="<?php the_title(); ?>"><?php short_title(); ?></a>              
</li>
    <?php } ?>
                 </ul>
           </div>
   </div>
    <?php} 
    else { 
    echo \'<div class="relatedpostAdd">
    <div id="related_posts1" class="reviews clear">
    <h3 style="margin:5px 0 ">Related Posts</h3>\' ?>
    <ul>
        <?php
    $args = array( \'numberposts\' => 4, \'orderby\' => \'rand\', 
                 \'post_status\' => \'publish\', \'offset\' => 1);
                  $rand_posts = get_posts( $args );

                  foreach( $rand_posts as $post ) : ?>
    <li>
 <div class="images_releted">
    <a class="post_thumbnail" href="<? the_permalink()?>" rel="bookmark"
    title="<?php the_title(); ?>"><?php echo the_post_thumbnail(\'thumbnail\') ?>
    </a>
</div>
    <a class="post_thumbnail_link" href="<?php the_permalink(); ?>">
     <?php short_title();?></a>
     </li>
    <?php endforeach; ?>
      </ul>
   </div>
</div>
    <?php }
        }
    $post = $orig_post;
    wp_reset_query(); 
    }
    }
    add_action(\'thesis_hook_after_post_box_related_posts\',\'related_posts\');
?>
我在帖子详细信息页面上获取错误

 Internal Server Error
    The server encountered an internal error or misconfiguration and
    was unable to  complete your request.......................
    a 500 Internal Server Error error was encountered while trying to use 
    an ErrorDocument to handle the request.

2 个回复
最合适的回答,由SO网友:Sanjay Nakate 整理而成

我已经解决了这个问题,我在测试服务器上测试了这个代码

我在帖子详细信息页面上看到错误错误是Fatal error: Call to undefined function short_title()

看到这一点后,我删除了函数代码short_title(); 从我的custom.php 并替换为the_title(); 显示标题。我已经检查了网站,一切都很好。

但我仍然不明白为什么这个函数short_title(); 无法在我的生产服务器上工作以及为什么它会引发Internal Server Error

除了这个错误Fatal error: Call to undefined function short_title()

SO网友:H. Guerrero cruzgloriosa.org

检查here

阅读安装注释

结束

相关推荐

WP_Query displaying ALL posts

我不明白为什么我的WP_Query 始终显示所有已发布的帖子,无论我在参数中输入了什么。<?php $args = array(\'numberposts\' => 1, \'meta_key\' => \'display\', \'meta_value\' => \'about\' ); $about_preview

按类别分类的相关帖子引发内部服务器错误 - 小码农CODE - 行之有效找到问题解决它

按类别分类的相关帖子引发内部服务器错误

时间:2014-11-07 作者:Sanjay Nakate

我正在使用wordpress 4.1中的论文,我试图使用下面的功能按类别显示相关帖子,但当我转到帖子详细信息页面时,它会引发内部服务器错误。我在另一个网站上使用了相同的代码,该网站上的代码运行良好,两个网站上的每个代码单词都是相同的。我在这里被绊住了。我在php中增加了wordpress内存限制。ini文件内存限制,但也不起任何作用。所以请引导我使用下面的代码显示相关帖子。我想知道我在另外两个网站上使用的代码是什么,这两个网站都有论文主题,而且效果很好。

<?php

    function related_posts() {
      if ( is_single() ) {
       global $post;
         $categories = get_the_category();
          foreach ($categories as $category)
           {
      ?>
 <div class="relatedpostAdd">
 <h3 style="margin:5px 0 ">More From <?php echo $category->name; ?></h3>
 <ul>
 <?php
       $posts = get_posts(\'numberposts=4&category=\'. $category->term_id);
         foreach($posts as $post)
          {
       ?>
 <li>
     <div class="images_releted">
       <a class="post_thumbnail" href="<? the_permalink()?>" rel="bookmark" title="<?php   
           the_title(); ?>"><?php echo the_post_thumbnail(\'thumbnail\') ?>
          </a>
     </div>
    <a class="post_thumbnail_link" href="<? the_permalink()?>" rel="bookmark" 
    title="<?php the_title(); ?>"><?php short_title(); ?></a>               
 </li>
        <?php } ?>
                  </ul>
 </div>
    <?php } ?>
<?php
     $orig_post = $post;
       global $post;
        $tags = wp_get_post_tags($post->ID);
        if ($tags) {
        $tag_ids = array();
        foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
           $args=array(
                       \'tag__in\' => $tag_ids,
                       \'post__not_in\' => array($post->ID),
                       \'posts_per_page\'=>4,
                       \'caller_get_posts\'=>1,
                       \'orderby\'=>\'rand\'
                                          );          
        $my_query = new wp_query( $args );
          if( $my_query->have_posts() ) 
          {
           echo \'<div class="relatedpostAdd">
                 <div id="related_posts1" class="reviews clear">
                 <h3 style="margin:5px 0 ">Related Posts</h3>
                 <ul>\';
         while( $my_query->have_posts() ) 
         {
            $my_query->the_post(); 
        ?>
 <li>
  <div class="images_releted">
     <a class="post_thumbnail" href="<? the_permalink()?>" rel="bookmark" 
     title="<?php the_title(); ?>"><?php echo the_post_thumbnail(\'thumbnail\') ?>
     </a>
  </div>
    <a class="post_thumbnail_link" href="<? the_permalink()?>" rel="bookmark" 
     title="<?php the_title(); ?>"><?php short_title(); ?></a>              
</li>
    <?php } ?>
                 </ul>
           </div>
   </div>
    <?php} 
    else { 
    echo \'<div class="relatedpostAdd">
    <div id="related_posts1" class="reviews clear">
    <h3 style="margin:5px 0 ">Related Posts</h3>\' ?>
    <ul>
        <?php
    $args = array( \'numberposts\' => 4, \'orderby\' => \'rand\', 
                 \'post_status\' => \'publish\', \'offset\' => 1);
                  $rand_posts = get_posts( $args );

                  foreach( $rand_posts as $post ) : ?>
    <li>
 <div class="images_releted">
    <a class="post_thumbnail" href="<? the_permalink()?>" rel="bookmark"
    title="<?php the_title(); ?>"><?php echo the_post_thumbnail(\'thumbnail\') ?>
    </a>
</div>
    <a class="post_thumbnail_link" href="<?php the_permalink(); ?>">
     <?php short_title();?></a>
     </li>
    <?php endforeach; ?>
      </ul>
   </div>
</div>
    <?php }
        }
    $post = $orig_post;
    wp_reset_query(); 
    }
    }
    add_action(\'thesis_hook_after_post_box_related_posts\',\'related_posts\');
?>
我在帖子详细信息页面上获取错误

 Internal Server Error
    The server encountered an internal error or misconfiguration and
    was unable to  complete your request.......................
    a 500 Internal Server Error error was encountered while trying to use 
    an ErrorDocument to handle the request.

2 个回复
最合适的回答,由SO网友:Sanjay Nakate 整理而成

我已经解决了这个问题,我在测试服务器上测试了这个代码

我在帖子详细信息页面上看到错误错误是Fatal error: Call to undefined function short_title()

看到这一点后,我删除了函数代码short_title(); 从我的custom.php 并替换为the_title(); 显示标题。我已经检查了网站,一切都很好。

但我仍然不明白为什么这个函数short_title(); 无法在我的生产服务器上工作以及为什么它会引发Internal Server Error

除了这个错误Fatal error: Call to undefined function short_title()

SO网友:H. Guerrero cruzgloriosa.org

检查here

阅读安装注释

相关推荐

是否可以取消对特定帖子类型的POSTS_PER_PAGE限制?

我想知道我是否可以取消特定帖子类型的posts\\u per\\u页面限制。在存档中。php页面我显示不同的帖子类型,对于特定的“出版物”帖子类型,我想显示所有帖子。我如何在不影响传统“post”类型的情况下实现这一点?