我想根据我博客的语言(法语和英语)自动显示帖子附件(PDF)。
当帖子以法语版本显示时,我想显示法语PDF,当帖子以英语显示时,显示英语PDF。
我使用qtranslate插件,并且我想使用附件的标题(“fr”或“en”)来创建一种条件标记。
我尝试了下面的代码,但它不起作用。你有什么办法帮我吗?
多谢了,德姆。
<!-- PDF EN -->
<?php if(qtrans_getLanguage()==\'en\'): ?>
<?php
if ( $attachments = get_children( array(
\'post_type\' => \'attachment\',
\'post_mime_type\' => array(\'application/doc\',\'application/pdf\',\'application/msword\'),
\'numberposts\' => 1,
\'post_status\' => null,
\'post_parent\' => $post->ID,
))) ;
foreach ($attachments as $attachment) {
if ($attachment->post_excerpt == \'en\') {
echo \'<a href="\' . wp_get_attachment_url( $attachment->ID ) . \'"><img src="\' .get_bloginfo(\'template_directory\') . \'/images/pdf.png" alt="Pdf" class="pdf" /></a>\';
echo \'\';
}
}
?>
<?php endif; ?>
<!-- PDF FR -->
<?php if(qtrans_getLanguage()==\'fr\'): ?>
<?php
if ( $attachments = get_children( array(
\'post_type\' => \'attachment\',
\'post_mime_type\' => array(\'application/doc\',\'application/pdf\',\'application/msword\'),
\'numberposts\' => 1,
\'post_status\' => null,
\'post_parent\' => $post->ID,
))) ;
foreach ($attachments as $attachment) {
if ($attachment->post_excerpt == \'fr\') {
echo \'<a href="\' . wp_get_attachment_url( $attachment->ID ) . \'"><img src="\' .get_bloginfo(\'template_directory\') . \'/images/pdf.png" alt="Pdf" class="pdf" /></a>\';
echo \'\';
}
}
?>
<?php endif; ?>