0
我希望根据我的博客(法语和英语)的语言自动显示帖子附件(PDF)。如何根据标题值在Wordpress中显示帖子附件
当帖子显示为法文版本时,我想显示法文PDF,并且当帖子用英文显示时,英文显示。
我使用qtranslate插件和我虽然使用附件的标题(“fr”或“en”)来创建一种条件标签。
我试过了下面的代码,但它不起作用。你有什么想法来帮助我吗?
非常感谢, Dem。
<!-- 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; ?>
哪些部分不工作多媒体文件的语言?它是有条件的吗? – mikevoermans 2012-04-05 17:50:18
谢谢你帮助我,mikevoermans。英语是好的,但是当我用法语版(=默认语言)开启时,PDF不显示。 OMG! – 2012-04-05 18:22:52
OMG!通过写这个评论,我找到了解决方案! “'numberposts'=> 1,”应该被删除。再次感谢你! – 2012-04-05 18:27:41