【发布时间】:2016-03-27 23:34:52
【问题描述】:
大家好,我有一个使用 wp-types 插件的 PDF 文件的帖子类型附件。实际上脚本工作正常并在列表中显示所有 PDF 文件,但我需要在新窗口中打开它们。知道如何解决这个问题并使帖子类型类别中的每个文件都在新窗口中打开吗?
我知道如何将其添加到普通 HTML 文档中或使用带有永久链接的 href。
<a href="#" title="My PDF File Title" target="_blank">PDF File</a>
例如,我有类似的 PDF 单个文件,代码如下,并且工作正常:
<a href="<?php echo types_render_field("main-pdf");?>" target="_blank" title="Download <?php the_title(); ?> - Specifications"><i class="fa fa-file-pdf-o"></i> Download PDF Specification for <?php the_title();?></a>
我无法使用下面的代码在新窗口中打开每个文件,例如按照这个 WordPress 指南“将附加的图像和标题显示为列表”访问link (WordPress Codex)
target="blank"
对下面的代码有什么建议或解决方案吗?
<?php
$args = array(
'post_type' => 'attachment',
'post_status' => 'any',
'target' => '_blank', // a try this but not working
'tax_query' => array(
array(
'taxonomy' => 'media_category',
'field' => 'link',
'terms' => 137
)
)
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li class="cataloguelist">';
echo '<i class="fa fa-file-pdf-o"></i>';
echo the_attachment_link( $attachment->ID, true);
echo apply_filters( 'the_title', $attachment->post_title );
echo '</li>';
}
} else {
// no attachments found
}
wp_reset_postdata();?>
【问题讨论】:
标签: php wordpress custom-post-type