【发布时间】:2020-08-13 14:15:59
【问题描述】:
我正在使用 domPDF 在我网站的某些页面上生成 PDF
我遇到的问题是它不允许我使用重复值(通过任何类型的循环),它似乎不想在创建 PDF 时生成它们。
如果我将转发器字段本身称为变量,它会返回“数组”,所以我认为它可以以某种方式工作。
似乎首先需要生成中继器,然后将其包含在内(可能作为变量?),但我不确定如何执行此操作。
有人知道我怎样才能让它工作吗?
这是我的 ACF 中继器代码:
<?php if( have_rows('team_contact_details') ): ?>
<div class="profile-item">
<ul class="list-contact">
<?php while( have_rows('team_contact_details') ): the_row(); ?>
<li>
<div class="list-contact-letter">
<?php the_sub_field("contact_label"); ?>
</div>
<div class="list-contact-detail">
<?php
if(get_sub_field('contact_link') == 'phone' ) {
echo '<a href="tel:' . get_sub_field("phone_number") . '">' . get_sub_field("phone_number") . '</a>';
} else if(get_sub_field('contact_link') == 'email' ) {
echo '<a href="mailto:' . get_sub_field("email_address") . '">' . get_sub_field("email_address") . '</a>';
}
?>
</div>
</li>
<?php endwhile; ?>
</ul>
</div>
<?php endif; ?>
这是我的 domPDF 代码:
//Print PDF
require_once get_template_directory() . '/dompdf/autoload.inc.php';
use Dompdf\Dompdf;
$content = '
<html>
<head></head>
<body>
<div class="person">
<img src="' . get_field('page_image') . '"/>
</div>
<h1>' . get_the_title() . '</h1>
<div class="pdf-label">' . get_field('team_academic') . '</div>
<div class="pdf-label">' . get_field('team_position') . '</div>
<<<< Attempting to put repeater values here as unordered list >>>>
</body>
</html>
';
// instantiate and use the dompdf class
$dompdf = new Dompdf(array(
'enable_remote' => true
)
);
$dompdf->loadHtml($content);
// (Optional) Setup the paper size and orientation
$dompdf->set_paper( 'letter' , 'portrait' );
// Render the HTML as PDF
$dompdf->render();
$doctitle = get_the_title();
$dompdf->stream($doctitle);
谢谢
【问题讨论】:
标签: wordpress advanced-custom-fields dompdf