首页 文章

如何根据 Headers 值在Wordpress中显示帖子附件

提问于
浏览
0

我想根据我的博客语言(法语和英语)自动显示帖子附件(PDF) .

当帖子以法语版本显示时,我想显示法语PDF,当帖子以英语显示时,英语版本 .

我使用qtranslate插件,但我使用附件的 Headers (“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; ?>

1 回答

相关问题