Module to get WordPress blog posts and display them in Magneto CMS pages. Blog posts to CMS pages are added as widgets so this will work in all sorts on Magento setups, like with Luma or any other Magento theme or with some ScandiPWA theme
- Will add config to specify source blog to get posts from.
- Will use cron to get blog post data
- Will add widget to select blog posts for CMS page
- Will show blog post cards on a CMA page
To install dependencies for the module run
composer require scandipwa/installer
composer require scandipwa/customization
To get cron installed run
magento cache:clean
magento cron:run
magento cron:run
Integration Settings
To add settings where should Magento get WordPress blog articles for each store go to Stores → Configuration → ScandiPWA → WordPress Integration and save source Url. Use URL of main url of the blog
New posts from blog will be pulled to Magento every night.
Blog post post display
To see blog posts on a CMA page open this page in the admin f.e. Content → Pages → Homepage
Create a new Row and add Columns to it if necessary using Page builder tools
Create a new Text element and select Insert Widget
As Widget Type select WordPress Post and select a post.
To change template use example module from app/code.
- Copy it to your project
- Rename
MyVendorNamefolder to match your project name or vendor - Replace in all files
MyVendorNamewith you project name or vendor - Adjust template currently in
app/code/MyVendorName/WordPressIntegration/view/frontend/templates/widget/wordpress_post.phtml
To get all legacy posts, you can use this cli command magento wordpress:get-posts and pass a custom url to it
https://some-site.com/wp-json/wp/v2/posts?page=2 - This will download posts from page 2
https://some-site.com/wp-json/wp/v2/posts?per_page=100 - This will download first 100 posts
https://some-site.com/wp-json/wp/v2/posts/123 - This will download post with id 123
More info on WordPress API https://developer.wordpress.org/rest-api/reference/#rest-api-developer-endpoint-reference
Example usage of command
magento wordpress:get-posts --url=https://some-site.com/wp-json/wp/v2/posts?page=2 --store-id=1
Manual cron execution
bin/n98-magerun2.phar sys:cron:run wordpress_get_posts
or
magento cron:run --group=wordpress
You can find the following functionality implemented in this module
-
etc/widget.xmlWidget configuration. It defines widget layout and custom icon use will see in CMA elements in tha Magento admin -
view/adminhtml/web/wordpress_post.pngCustom icon for widget element in Magento admin so users can distinguish among different widgets that are added to page -
view/frontend/templates/widget/wordpress_post.phtmlMagento template file used to render widget content for frontend -
Block/Widget/WordPressPost.phpWidget block class with a few useful functions for rendering the posts content. These functions are used in.phtmltemplate -
Cron/GetBlogPosts.phpCron command implementation to get WordPres posts -
Console/Command/GetWordPressPosts.phpMagento cli command implementation that will process cli parameters adn will call a function fromGetBlogPostscron to get blog posts -
ModelHere you will find classes that implement WordPress posts so Magento can store them in the DB and can work with them -
Controller/Adminhtml/Block/Widget/Chooser.phpThis file is responsible for first widget popup and will load info about selected WordPress post if we are editing some widget in the admin -
Block/Adminhtml/Widget/Chooser.phpThis class is responsible for WordPress post selection table. It has functions to prepare and load WordPress post collection and js functions to handle user click on some post to select it. -
Block/Adminhtml/Grid/ColumnCode to process image and video columns, so they look nicer in the admin grid.
- Add last cron error and execution time to be visible in WordPress settings section
- Add support for selectable post image size. Currently, 'large' image size will be downloaded
- Add support for full blog post content