Question

EDIT 01-28-13: Revised to clarify my question.

I'm using Magento 1.7.0.0 and FishPig WP full integration. We have successfully listed products from specific category and from all categories but was wondering if we can exclude in some cases from specified category. I found solutions to do this in functions.php within WordPress but this does not seem to work.

Here is the current code that displays posts from all categories. We'd like to add an exception so WordPress 1 Category can be excluded.

Here is the code that displays from all categories which I'd like to NOT include category "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
      }
  ?>

Let me know if I need to clarify myself. I appreciate your time.

Was it helpful?

Solution

    //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
      }
  ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top