我想让代码在页脚中显示页面标题列表。我在中生成了以下代码functions.php:
add_action(\'yamada_action\', \'list_page_2\');
function list_page_2() {
global $title_yama;
$title_yama = \'\';
$args = array(
\'post_type\' => \'page\',
\'post_status\' => \'publish\',
);
$queries_yama = new WP_Query($args);
if($queries_yama->have_posts()): while ($queries_yama->have_posts()):$queries_yama->the_post();
$title_yama .= \'<li class="aaa"><a href="\' .get_permalink(). \'">\'.the_title().\'</a></li>\';
endwhile; endif;
wp_reset_query();
return $title_yama;
}
我输入了
footer.php 以下代码:
<?php do_action(\'yamada_action\'); ?>
但是,代码只显示文本作为标题。
我应该如何生成代码以输出包含HTML代码的内容?
最合适的回答,由SO网友:X-MUK-625 整理而成
非常感谢你的建议。我可以如下解决这个问题。
作用php
add_action(\'yamada_action\', \'list_page_2\');
function list_page_2() {
$title_yama = \'\';
$args = array(
\'post_type\' => \'page\',
\'post_status\' => \'publish\',
);
$queries_yama = new WP_Query($args);
if($queries_yama->have_posts()): while ($queries_yama->have_posts()):$queries_yama->the_post();
$title_yama .= \'<li class="aaa"><a href="\'.esc_url(get_the_permalink()). \'">\'.get_the_title().\'</a></li>\';
endwhile; endif;
wp_reset_query();
echo $title_yama;
}
页脚。php
<?php do_action(\'yamada_action\'); ?>
我修复了它如下。
删除global $title_yama;
修复了href属性get_permalink() 到esc_url(get_the_permalink())内部固定<a> 标签the_title() 到get_the_title()固定
return 到
echo