1

编辑 01-28-13:修改以澄清我的问题。

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

这是显示所有类别帖子的当前代码。我们想添加一个例外,以便可以排除 WordPress 1 类别。

这是从我不想包括类别“Press_HomePage”的所有类别中显示的代码:

    $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
      }
  ?>

让我知道是否需要澄清自己。我很感激你的时间。

4

1 回答 1

1
    //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
      }
  ?>
于 2013-01-29T16:50:42.680 回答