0

您如何获得 single.php 上的帖子类别?

我试过了:

<h1><?php echo $this->escapeHtml($post->get_the_category()) ?></h1>

&

   <?php echo $this->escapeHtml($post->get_category_parents( $cat, true, ' &raquo; ' )) ?>

&

<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; ?>

我正在通过 Magento 的 Fishpig WordPress 集成来开发 WordPress,因此文件路径是 template/wordpress/post/view.phtml。

4

3 回答 3

3

托马斯是正确的;您不能在 Magento 模板文件中使用 WordPress 代码,即使该模板文件正在集成 WordPress。没有包含任何 WP 库代码,因此您包含的 WP 函数不存在。

不过,仍然可以通过 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; ?>
于 2014-08-15T17:25:56.440 回答
0

尝试写不$post喜欢。

get_the_category( get_the_ID() );

代替$post->get_the_category($post->ID)

于 2014-08-14T11:18:39.043 回答
-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;
于 2015-02-17T19:36:36.027 回答