|
So, we needed to achieve nodal content for CMS pages. So, basically what we did was setup wp to manage CMS page content via the following mechanism. It is fairly crude at this point, but it does work. I would like to get feedback on problems, or improvements.
---------------------------
1. Download WP - http://wordpress.org/download/
2. Extract WP in a ‘wp’ directory at root
3. Create wp-config.php with the following:
<?php
function get_magento_path($path) { $backup = (strpos(getcwd(), 'wp-admin')) ? '../..' : '..'; return getcwd().'/'. $backup . '/' . $path; }
function parse_app_config($path = null) { $path = (empty($path)) ? get_magento_path('app/etc/local.xml') : $path; $config = array(); $xml = simplexml_load_file($path, null, LIBXML_NOCDATA); $config['db'] = $xml->global->resources->default_setup->connection->dbname; $config['un'] = $xml->global->resources->default_setup->connection->username; $config['pw'] = $xml->global->resources->default_setup->connection->password; $config['hp'] = $xml->global->resources->default_setup->connection->host; $config['key'] = $xml->global->crypt->key; return $config; }
$config = parse_app_config();
// ** MySQL settings ** // define('DB_NAME', $config['db']); // The name of the database define('DB_USER', $config['un']); // Your MySQL username define('DB_PASSWORD', $config['pw']); // ...and password define('DB_HOST', $config['hp']); // 99% chance you won't need to change this value define('DB_CHARSET', 'utf8'); define('DB_COLLATE', '');
// Change SECRET_KEY to a unique phrase. You won't have to remember it later, // so make it long and complicated. You can visit https://www.grc.com/passwords.htm // to get a phrase generated for you, or just make something up. define('SECRET_KEY', $config['key']); // Change this to a unique phrase.
// You can have multiple installations in one database if you give each a unique prefix $table_prefix = 'wp_'; // Only numbers, letters, and underscores please!
// Change this to localize WordPress. A corresponding MO file for the // chosen language must be installed to wp-content/languages. // For example, install de.mo to wp-content/languages and set WPLANG to 'de' // to enable German language support. define ('WPLANG', '');
/* That's all, stop editing! Happy blogging. */
define('ABSPATH', dirname(__FILE__).'/'); require_once(ABSPATH.'wp-settings.php'); ?>
4. Finish installing WP
Direct browser to: http://example.com/wp/wp-admin.php
5. Set a permalink structure, it doesn’t matter, which just so we get clean urls enabled
6. Create all the categories you want to have available
7. Go to /wp/wp-content/themes/<yourtheme>/archive.php
* Remove all the calls to header, sidebar, and footer functions
* Remove anything that directly links to the post (that would take you out of the magneto environment
* Change the id of “content” to “wp-content” so it does not conflict with anything in magento
8. Create a new directory in your template: /app/design/frontend/<interface>/<theme>/template/wp/
9. Create block templates for each WP category in the folder you just created
In each block, paste the following. You should only need to change the category variable.
<?php
$category = 'home_en';
# shouln't need to change anything below this line
$secure = ($_SERVER['SERVER_PORT'] == '443') ? true : false; $base_path = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK,$secure);
$url = $base_path.'wp/category/'.$category;
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
$response = curl_exec($ch);
if(curl_errno($ch)) { $response = print curl_error($ch); }
curl_close($ch);
echo $response;
?>
10. Create pages using Magento’s CMS for each category, and insert the following as contents for each (replacing home_en with your category names):
{{block type="core/template" template="wp/home_en.phtml" name="home_en"}}
11. At this point you should be done. Viewing the pages should give you the full article listing structured by wordpress.
Limitations:
This method does not yet support the ability to have comments, or to view specific post entries.
|