php - 动态生成的标题和 href 属性未正确添加到锚标记
问题描述
我想返回一个带有动态 href 和标题的链接。这就是我到目前为止所拥有的。我已经可以输出我的动态 ACF 字段get_field('acf_field_name')
,但我认为我没有得到下面的串联$buffer = "<a href='".get_field('acf_field_name') "'>".the_title()'</a>';
function qg_shortcode() {
$buffer = '<h3>Heading</h3>';
$download = get_field('acf_field_name');
$q = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 5
));
while ($q->have_posts()) {
$q->the_post();
$buffer = "<a href='".$download"'>".the_title()'</a>';
}
wp_reset_postdata();
return $buffer;
}
你能告诉我有什么问题吗?
解决方案
你concatenation operator(.)
在字符串之间丢失了。
$buffer = "<a href='" . $download . "'>" . the_title() . '</a>';
还要确保您是否有可能破坏您的 URL 的特殊字符,对其进行清理。
推荐阅读
- flutter - 如何在颤动中更改文本字段的晦涩字符?
- javascript - Map.get() 在异步函数中返回未定义
- python - 用python编辑文本文件中的字典
- python - Django 2.2.5 的密码重置问题
- python - Python Pandas 使用先例行值更新行中的值
- python - 在 numpy 数组中逐元素应用操作
- reactjs - 反应未将 className 样式应用于按钮
- javascript - Javascript延迟图像更改
- terminal - 设置 ZSH_THEME="agnoster" 没有任何作用(macOS Catalina)
- mediawiki - 在(MediaWiki)wiki 上显示远处的图像?