我正在使用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.
最合适的回答,由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()