首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Magento 1.7.0.0 FishPig -不包括类别

Magento 1.7.0.0 FishPig -不包括类别
EN

Stack Overflow用户
提问于 2013-01-27 05:44:09
回答 1查看 1.2K关注 0票数 1

编辑01-28-13:修订以澄清我的问题.

我使用Magento1.7.0.0和FishPig WP完全集成。我们已经成功地列出了特定类别和所有类别的产品,但不知道在某些情况下我们是否可以将产品排除在特定类别之外。我在functions.php中找到了在WordPress中这样做的解决方案,但这似乎不起作用。

下面是显示来自所有类别的帖子的当前代码。我们希望添加一个异常,以便可以排除WordPress 1类别。

这里显示的是所有类别的代码,我不想包含"Press_HomePage":类别

代码语言:javascript
复制
    $col_posts = Mage::getResourceModel('wordpress/post_collection')->addIsPublishedFilter();
    $posttotal = count($col_posts->getAllIds());
    $posttotid = $col_posts->getAllIds();

    //i<=2 means displays last 2 posts
    //display latest 2 posts...
    for ( $i=1; $i<=2; $i++ )
      {
  ?>
        <div class="blog">
          <h2><?php echo $col_posts->getItemById($posttotid[$posttotal-$i])->getPostDate(); ?></h2>
          <h1><?php echo $col_posts->getItemById($posttotid[$posttotal-$i])->getPostTitle(); ?></h1>
          <div style="float:left; margin-top:15px; margin-bottom:25px;">
          <?php 
            $featured_img = $this->getSkinUrl('images/pree_emty.png');
            if($featuredImage = $col_posts->getItemById($posttotid[$posttotal-$i])->getFeaturedImage())
              {
                $featured_img = $featuredImage->getAvailableImage();
              }
          ?>
            <img style="float: left;" src="<?php echo $featured_img; ?>" width="204" height="204" alt="" />

            <div style="float: left; width: 580px; padding: 10px;">
              <p><?php echo substr(strip_tags($col_posts->getItemById($posttotid[$posttotal-$i])->getPostContent()), 0, 400); ?></p>
              <p>
                <a href="<?php echo $col_posts->getItemById($posttotid[$posttotal-$i])->getUrl(); ?>">
                  <img src="<?php echo $this->getSkinUrl('images/view_btn.jpg'); ?>" width="170" height="32" alt="" />
                </a>
              </p>
            </div>
          </div>
        </div>
  <?php
      }
  ?>

如果我需要澄清的话请告诉我。我很感激你能抽出时间。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-01-29 16:50:42

代码语言:javascript
复制
    //loki - get all the post ids
    $col_posts = Mage::getResourceModel('wordpress/post_collection')->addIsPublishedFilter();
    $posttotid = $col_posts->getAllIds();

    //loki - get all the press ids
    $col_posts_press = Mage::getResourceModel('wordpress/post_collection')->addIsPublishedFilter()->addCategorySlugFilter('press_homepage');
    $posttotid_press = $col_posts_press->getAllIds();

    //loki - removing the press_homepage category from array and reindexing
    $blogposts = array_diff($posttotid, $posttotid_press);
    $blogposts = array_values($blogposts);
    $posttotal = count($blogposts);

    //i<=2 means displays last 2 posts
    //display latest 2 posts...

    for ( $i=1; $i<=2; $i++ )
      {

  ?>
        <div class="blog">
          <h2><?php echo $col_posts->getItemById($blogposts[$posttotal-$i])->getPostDate(); ?></h2>
          <h1><?php echo $col_posts->getItemById($blogposts[$posttotal-$i])->getPostTitle(); ?></h1>
          <div style="float:left; margin-top:15px; margin-bottom:25px;">
          <?php 
            $featured_img = $this->getSkinUrl('images/pree_emty.png');
            if($featuredImage = $col_posts->getItemById($blogposts[$posttotal-$i])->getFeaturedImage())
              {
                $featured_img = $featuredImage->getAvailableImage();
              }
          ?>
            <img style="float: left;" src="<?php echo $featured_img; ?>" width="204" height="204" alt="" />

            <div style="float: left; width: 580px; padding: 10px;">
              <p><?php echo substr(strip_tags($col_posts->getItemById($blogposts[$posttotal-$i])->getPostContent()), 0, 400); ?></p>
              <p>
                <a href="<?php echo $col_posts->getItemById($blogposts[$posttotal-$i])->getUrl(); ?>">
                  <img src="<?php echo $this->getSkinUrl('images/view_btn.jpg'); ?>" width="170" height="32" alt="" />
                </a>
              </p>
            </div>
          </div>
        </div>
  <?php
      }
  ?>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14544782

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档