1

EDIT 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 に答える