admin管理员组文章数量:1287633
I created a function in my functions.php to show related posts for a custom posttype. Because the original developer used a themebuilder, I need to use a shortcode to display this function on the front-end.
A part of the code I use is
if($related_cats_post->have_posts()):
while($related_cats_post->have_posts()): $related_cats_post->the_post();
$postsList .= '<li><a href="' . the_permalink() . '">' . the_title() . '</a></li>';
endwhile;
return '<ul>' . $postsList . '</ul>';
It gets the job almost done. The only problem is that because I use the_permalink() and the_title(), the link and the title shows up on top of the page and not in the unordered list as they supposed to do. I don't know why this happens and how to fix this. Is it maybe because I call the function within a shortcode?
Is there a way to fix this?
I created a function in my functions.php to show related posts for a custom posttype. Because the original developer used a themebuilder, I need to use a shortcode to display this function on the front-end.
A part of the code I use is
if($related_cats_post->have_posts()):
while($related_cats_post->have_posts()): $related_cats_post->the_post();
$postsList .= '<li><a href="' . the_permalink() . '">' . the_title() . '</a></li>';
endwhile;
return '<ul>' . $postsList . '</ul>';
It gets the job almost done. The only problem is that because I use the_permalink() and the_title(), the link and the title shows up on top of the page and not in the unordered list as they supposed to do. I don't know why this happens and how to fix this. Is it maybe because I call the function within a shortcode?
Is there a way to fix this?
Share Improve this question edited Sep 17, 2021 at 12:07 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Sep 17, 2021 at 9:42 RicardioRicardio 381 silver badge8 bronze badges1 Answer
Reset to default 3You need to use the equivalent functions that return their value. Those are get_the_permalink()
and get_the_title()
.
Most WordPress template functions that begin with the_
and echo their values have equivalent functions that return their values that begin with get_the_
,
本文标签: permalinksWordpress basic functions show on top in custom shortcode
版权声明:本文标题:permalinks - Wordpress basic functions show on top in custom shortcode 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741314929a2371857.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论