如何在single.php上获得帖子类别?
我试过了:
<h1><?php echo $this->escapeHtml($post->get_the_category()) ?></h1>
&安培;
<?php echo $this->escapeHtml($post->get_category_parents( $cat, true, ' » ' )) ?>
&安培;
<h1><?php echo $this->escapeHtml($post->get_the_category($post->ID)) ?></h1>
这是整个文件:
<?php $post = $this->getPost() ?>
<?php if ($post): ?>
<?php $helper = $this->helper('wordpress') ?>
<?php $author = $post->getAuthor() ?>
<div class="page-title post-title">
<h1><?php echo $this->escapeHtml($post->get_the_category($post->ID)) ?></h1>
<h1><?php echo $this->escapeHtml($post->getPostTitle()) ?></h1>
</div>
<div class="post-view">
<p class="post-date when"><?php echo stripslashes($this->__('<span class=\"by-author\"> by %s</span> on %s.', $post->getAuthor()->getDisplayName(), $post->getPostDate())) ?></p>
<?php echo $this->getBeforePostContentHtml() ?>
<div class="post-entry entry std<?php if ($post->getFeaturedImage()): ?> post-entry-with-image<?php endif; ?>">
<?php if ($post->isViewableForVisitor()): ?>
<!-- --><?php //if ($featuredImage = $post->getFeaturedImage()): ?>
<!-- <div class="featured-image left"><img src="--><?php //echo $featuredImage->getAvailableImage() ?><!--" alt="--><?php //echo $this->escapeHtml($post->getPostTitle()) ?><!--"/></div>-->
<!-- --><?php //endif; ?>
<?php echo $post->getPostContent() ?>
<?php else: ?>
<?php echo $this->getPasswordProtectHtml() ?>
<?php endif; ?>
</div>
<?php echo $this->getAfterPostContentHtml() ?>
<?php echo $this->getCommentsHtml() ?>
</div>
<?php endif; ?>
我正在通过Fishpig WordPress集成Magento来处理WordPress,因此文件路径为template / wordpress / post / view.phtml。
答案 0 :(得分:3)
尽管如此,仍然可以通过Magento代码获取所需的所有WP数据。要获取帖子类别,请使用以下代码:
<?php $categories = $post->getParentCategories() ?>
<?php if (count($categories) > 0): ?>
<?php foreach($categories as $category): ?>
<a href="<?php echo $category->getUrl() ?>"><?php echo $this->escapeHtml($category->getName()) ?></a>
<?php endforeach; ?>
<?php endif; ?>
答案 1 :(得分:0)
尝试在没有$post
的情况下写作。
get_the_category( get_the_ID() );
而不是$post->get_the_category($post->ID)
答案 2 :(得分:-1)
function getPages() {
$pages = Mage::getResourceModel('wordpress/page_collection')
->addIsViewableFilter()
->orderByMenuOrder()
->setOrderByPostDate()
->load();
return $pages;
}
$pages = getPages();
foreach ($pages as $post):
Collection goes here
endforeach;