2012-04-05 108 views
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; ?> 
+0

哪些部分不工作多媒體文件的語言?它是有條件的嗎? – mikevoermans 2012-04-05 17:50:18

+0

謝謝你幫助我,mikevoermans。英語是好的,但是當我用法語版(=默認語言)開啓時,PDF不顯示。 OMG! – 2012-04-05 18:22:52

+0

OMG!通過寫這個評論,我找到了解決方案! 「'numberposts'=> 1,」應該被刪除。再次感謝你! – 2012-04-05 18:27:41

回答

相關問題