【发布时间】:2014-02-17 16:50:55
【问题描述】:
在我的子主题中使用 wordpress 并编辑一些 PHP 代码,但在热门帖子的侧边栏小部件方面遇到了问题。
wordpress 中每篇受欢迎的博客文章都会准确显示在热门文章侧边栏中,单击故事标题将转到我博客上的单个故事页面。
此小部件中链接到我自己在 widgets.php 中的博客文章的正确代码是:
if ( $popular_posts->have_posts() ) {
$result .= '<div class="post-popular"><ul class="list">';
while ( $popular_posts->have_posts() ) {
$popular_posts->the_post();
$comments_text = sprintf( _n( '%1$s comment', '%1$s comments', get_comments_number(), APP_TD ), get_comments_number() );
$result .= '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a> - ' . $comments_text . '</li>';
}
$result .= '</ul></div>';
}
由于这是热门文章的侧边栏小部件,我希望侧边栏点击直接转到每篇文章的外部网站,而不是我的博客文章。
在每篇博客文章中都有一个直接外部链接,指向每篇文章的实际文章。 每个帖子都标记为以下代码 article_out_url
我尝试对 get_permalink() 进行以下代码编辑,使其 get_permalink($url) 转到每个外部,例如:
$url = get_post_meta( $post->ID, 'article_out_url', true );
$result .= '<li><a href="' . get_permalink($url) . '">' . get_the_title() . '</a> - ' . $comments_text . '</li>';
如:
if ( $popular_posts->have_posts() ) {
$result .= '<div class="post-popular"><ul class="list">';
while ( $popular_posts->have_posts() ) {
$url = get_post_meta( $post->ID, 'article_out_url', true );
$popular_posts->the_post();
$comments_text = sprintf( _n( '%1$s comment', '%1$s comments', get_comments_number(), APP_TD ), get_comments_number() );
$result .= '<li><a href="' . get_permalink($url) . '">' . get_the_title() . '</a> - ' . $comments_text . '</li>';
}
$result .= '</ul></div>';
}
但是,这不起作用。而不是去外部链接,点击链接只是去我的根域。甚至没有关于该主题的个人帖子。
我被难住了。关于如何让每篇文章链接转到每篇文章的 article_out_url URL 的任何想法?谢谢。
【问题讨论】: