在我的功能中。php我有一个函数,允许我放置“similar posts by categories“:
functions.php:
function alep_related_posts_by_category() {
global $post;
// We should get the first category of the post
$categories = get_the_category( $post->ID );
$first_cat = $categories[0]->cat_ID;
$args = array(
// It should be in the first category of our post:
\'category__in\' => array( $first_cat ),
// Our post should NOT be in the list:
\'post__not_in\' => array( $post->ID ),
\'posts_per_page\' => 3
);
$posts = get_posts( $args );
if( $posts ) {
$output = \'<div class="sidebar-entries">\';
foreach( $posts as $post ) {
setup_postdata( $post );
$post_title = get_the_title();
$permalink = get_permalink();
$output .= \'<p class="title clickablediv"><a href="\' . $permalink . \'" title="\' . esc_attr( $post_title ) . \'">\' . $post_title . \'</a></p>\';
}
$output .= \'</div>\';
} else {
$output .= \'<p>Sorry, no other posts matched this category.</p>\';
}
echo $output;
}
我刚刚发现如果我将此函数与
<?php edit_post_link(\'Edit article\', \'<p>\', \'</p>\'); ?>
这将导致“编辑帖子链接”链接到错误的帖子。我不知道为什么这些功能是相关的。我知道如果我删除上面的函数
edit_post_link
很好用。
这是怎么回事?如何解决此问题?