2016-03-14 99 views
0

我在我的項目中有兩個帖子類別,並且這兩個類別都使用不同的視圖。我正在使用fishpig插件來添加和分類帖子,但這兩個類別帖子都使用相同的view.phtml模板來顯示帖子。如何在Magento Fishpig的自定義模板中顯示類別帖子?

<wordpress_post_view> 
    <reference name="content"> 
     <block type="wordpress/post_view" name="wp.post.view" template="wordpress/post/view.phtml"> 
      <block type="core/text_list" name="post.content.before" as="before_post_content" /> 
      <block type="core/text_list" name="post.content.after" as="after_post_content"> 
       <block type="wordpress/post_meta" name="wp.post.view.meta" as="meta" after="-" template="wordpress/post/meta.phtml"> 
        <action method="setDisplayPreviousNextLinks"><display>1</display></action> 
       </block> 
      </block> 
      <block type="wordpress/post_view_comment_wrapper" name="wp.post.view.comments" as="comments" template="wordpress/post/view/comment/wrapper.phtml"> 
       <block type="wordpress/post_view_comments" name="wp.post.view.comments.list" as="comment_list" template="wordpress/post/view/comments.phtml" /> 
       <block type="wordpress/post_view_comment_pager" name="wp.post.view.comments.pager" as="pager"/> 
       <block type="wordpress/post_view_comment_form" name="wp.post.view.comments.form" as="form" template="wordpress/post/view/comment/form.phtml"> 
        <block type="core/text_list" name="wp.post.view.comments.form.before_end" as="before_form_end" /> 
       </block> 
      </block> 
     </block> 
    </reference> 
    </wordpress_post_view> 

有沒有什麼辦法可以分離發佈視圖?

回答

0

做到這一點的最好方法是使用2種不同的帖子類型,而不是按類別拆分帖子。這將允許您爲每個帖子類型分別設置一個單獨的模板。

如果您想使用類別,您需要自定義view.phtml並添加一個檢查來查看當前帖子所屬的類別,然後顯示相應的內容。

+0

謝謝本,分類的帖子應該使用郵政類型和分類擴展嗎? –

+0

如果你想使用類別,你需要調用$ post-> getTermCollection('category')並遍歷這些類別來確定這個帖子在哪個類別。要按帖子類型拆分,你需要Post類型的add-延期。 –

+0

雖然我試圖使用getTermCollection('category')它顯示**調用成員函數getTermCollection()上的一個非對象**可以請你分享我的語法? –

相關問題