You are here:  » Drip Feeding Products into Wordpress Posts Automatically


Drip Feeding Products into Wordpress Posts Automatically

Submitted by aero_mansoor on Wed, 2010-05-19 17:14 in

Question

I want to be able to add posts automatically containing the product name as the title, product description and image etc as the content of the wordpress post. So say 10 products a day will be published as posts automatically. What would be the best way round to do something like this?

Thanks

Submitted by support on Thu, 2010-05-20 11:21

Hi,

Are you able to import posts IN to WordPress from an RSS feed?

If that would be an option, I can help you modify the RSS export script from this thread into a version that can be made to progress through the database without returning the same 10 items again...

Cheers,
David.

Submitted by aero_mansoor on Thu, 2010-05-20 11:58

Hi David,

Thank You for your reply. Yes I can import posts into wordpress from an RSS feed.

Yes please do help me modify the RSS export script.

Cheers

Submitted by support on Fri, 2010-05-21 10:07

Hi,

I have thought about this and I think the best thing to do is have a table in the database to record the progress of the RSS feed through the products table, so each time you request rss.php it checks a new `drip` table to get the start value to use, and then increments the value by the number of items you want each time you run rss.php (defaults to 10 in the code below).

To do this, firstly, upload the following as dbmod.php and then browse to it:

dbmod.php

<?php
  
require("includes/common.php");
  
$sql "DROP TABLE `".$config_databaseTablePrefix."drip`";
  
database_queryModify($sql,$result);
  
$sql "CREATE TABLE `".$config_databaseTablePrefix."drip`
    (
    `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    `start` INT ( 11 ) NOT NULL
    ) ENGINE = MYISAM
    "
;
  
database_queryModify($sql,$result);
  
$sql "INSERT INTO `".$config_databaseTablePrefix."drip` SET start='0'";
  
database_queryModify($sql,$result);
  print 
"Done.";
?>

You can also browse to dbmod.php again whenever you want to reset the starting point back to 0.

Next here, is a modified version of the rss.php script that has the Buy URL as link instead of the link to the product on your Price Tapestry installation, although this can of course be changed to whatever you need if that's not suitable. You can change the number of products output in the feed each time on line 1 by changing the value of $count...

rss.php

<?php
  $count = 10;
  require("includes/common.php");
  header("Content-Disposition: attachment; filename=products.xml");
  header("Content-Type: text/xml");
  print "<?xml version='1.0' encoding='UTF-8'?>";
  print "<rss>";
  print "<channel>";
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."drip`";
  database_querySelect($sql,$rows);
  $start = $rows[0]["start"];
  $sql = "UPDATE `".$config_databaseTablePrefix."drip` SET start = start + ".$count;
  database_queryModify($sql,$result);
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` LIMIT ".$start.",".$count;
  if (database_querySelect($sql,$rows))
  {
    foreach($rows as $row)
    {
      print "<item>";
      if ($config_useRewrite)
      {
        $link = "http://".$_SERVER["HTTP_HOST"].tapestry_buyURL($row);
      }
      else
      {
        $link = $row["buy_url"];
      }
      print "<title>".$row["name"]."</title>";
      print "<link>".$link."</link>";
      print "<description>".$row["description"]."</description>";
      print "</item>";
    }
  }
  print "</channel>";
  print "</rss>";
?>

Hope this helps!

Cheers,
David.

Submitted by Rocket32 on Sun, 2020-08-09 00:01

Hello David,

I want to add a slight adjust to the above rss drip. How do I incorporate an adjustment schedule that over rides the rss.php call? I want the product to change on a schedule instead of a call to rss.php with preferably random selections. Maybe 2 or 3 times a day, or week or something similar to cron for the product change. IF rss.php is clicked, or called 100 times a day, I would only want 1, 2, or possibly 3 products dripped that day & the next day add more from table.

Can this be accomplished with either code below is code below for 1 product call;

RSS 1 Call

<?php
  $baseURL = "http://www.example.com"; // URL of your site without trailing "/"
  $count = 1;
  require("includes/common.php");
  header("Content-Disposition: attachment; filename=products.xml");
  header("Content-Type: text/xml");
  print "<?xml version='1.0' encoding='UTF-8'?>";
  print "<rss version='2.0'>";
  print "<channel>";
  print "<title>RSS feed Example.com</title>";
  print "<link>".$baseURL.$config_baseHREF."</link>";
  print "<description>RSS feed Example.com</description>";
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."drip`";
  database_querySelect($sql,$rows);
  $start = $rows[0]["start"];
  $sql = "UPDATE `".$config_databaseTablePrefix."drip` SET start = start + ".$count;
  database_queryModify($sql,$result);
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` LIMIT ".$start.",".$count;
  if (database_querySelect($sql,$rows))
  {
    foreach($rows as $product)
    {
      print "<item>";
      if ($config_useRewrite)
      {
        $href = "product/".tapestry_hyphenate($product["name"]).".html";
      }
      else
      {
        $href = "products.php?q=".urlencode($product["name"]);
      }
      print "<title>".$product["name"]." price $".$product["price"]." </title>";
       print "<link>".$baseURL.$config_baseHREF.$href."</link>";
       print "<guid>".$baseURL.$config_baseHREF.$href."</guid>";
      print "<description><![CDATA[";
      print "<img src='".$product["image_url"]."' /><br />";
      print "<p>".$product["description"]."</p>";
      print "]]></description>";
      print "</item>";
    }
  }
  print "</channel>";
  print "</rss>";
?>

RSS 2 Call

<?php
  $baseURL = "http://www.example.com"; // URL of your site without trailing "/"
  require("includes/common.php");
  header("Content-Type: text/xml");
  print "<?xml version='1.0' encoding='UTF-8'?>";
  print "<rss version='2.0'>";
  print "<channel>";
  print "<title>RSS Product Export</title>";
  print "<link>".$baseURL.$config_baseHREF."</link>";
  print "<description>RSS Product Export</description>";
  $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` ORDER BY RAND() LIMIT 1";
  if (database_querySelect($sql,$rows))
  {
    foreach($rows as $product)
    {
      print "<item>";
      if ($config_useRewrite)
      {
        $href = "product/".tapestry_hyphenate($product["name"]).".html";
      }
      else
      {
        $href = "products.php?q=".urlencode($product["name"]);
      }
      print "<title>".$product["name"]."</title>";
      print "<link>".$baseURL.$config_baseHREF.$href."</link>";
      print "<guid>".$baseURL.$config_baseHREF.$href."</guid>";
      print "<description><![CDATA[";
      print "<img src='".$product["image_url"]."' /><br />";
      print "<p>".$product["description"]."</p>";
      print "]]></description>";
      print "</item>";
    }
  }
  print "</channel>";
  print "</rss>";
?>

Submitted by Rocket32 on Sun, 2020-08-09 04:48

Also how do I drip featured or popular views products in rss feed?

Submitted by support on Mon, 2020-08-10 07:35

Hi,

You can easily fix the selection by day by passing the date as the seed parameter to MySQL's RAND() function, so where you have the following line in the second script;

   $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` ORDER BY RAND() LIMIT 1";

...REPLACE with:

   $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` ORDER BY RAND(".date("Ymd").") LIMIT 1";

To do the same but limited to Featured Products use:

   $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name IN (SELECT name FROM `".$config_databaseTablePrefix."featured`) ORDER BY RAND(".date("Ymd").") LIMIT 1";

For popular products he first script could be changed to order by views (if you haven't already added the popular products mod this is based on the code from this comment) so where you have the following code:

   $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` LIMIT ".$start.",".$count;

...REPLACE with:

   $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` ORDER BY views DESC LIMIT ".$start.",".$count;

Hope this helps!

Cheers,
David.
--
PriceTapestry.com