Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • James Taylor 14 posts 124 karma points
    Jun 26, 2017 @ 13:26
    James Taylor
    0

    Best way to implement mechanism which "syncs" content to Wordpress site

    Hi All,

    Just looking for a bit of advice on how to approach a particular problem.

    We have an Umbraco news/magazine site and several Wordpress sites which sell our commercial services/offerings. We'd like to "sync" the news items uploaded to the main Umbraco site to the Wordpress ones.

    News stories get uploaded once a week and are rarely updated.

    My initial though was to do this with an RSS feed, however it seems that a better approach may be to save each news item to the Wordpress posts database using a weekly cron job. The Wordpress part I can do, but how to handle the Umbraco bit? Or... any other ideas? I see there's a REST-API, but I'm not sure how I could use this with PHP.

    Thanks!

    (Disclaimer: I'm a Wordpress/PHP dev and know just enough Umbraco/C# to be dangerous).

  • Alex Skrypnyk 6133 posts 23952 karma points MVP 7x admin c-trib
    Jun 26, 2017 @ 13:40
    Alex Skrypnyk
    0

    Hi James

    The best way to do it will be creating API methods in Umbraco solution and then use it in WordPress sites.

    Read more about API controllers in Umbraco, it's pretty easy to create:

    https://our.umbraco.org/documentation/reference/routing/webapi/

    Thanks,

    Alex

  • James Taylor 14 posts 124 karma points
    Jun 26, 2017 @ 15:32
    James Taylor
    0

    Thanks Alex,

    Can you recommend a tutorial on how to create an API controller? I Googled and couldn't find anything useful... (simpler is better).

    Using this as a basis, I created a file called ProductsController.cs in App_Code and pasted in the following:

    public class ProductsController : UmbracoApiController
    {       
        public IEnumerable<string> GetAllProducts()
        {
            return new[] { "Table", "Chair", "Desk", "Computer", "Beer fridge" };
        }
    }
    

    However, I get an CS0246: The type or namespace name 'UmbracoApiController' could not be found error when visiting the site. I guess I need to include some dependencies, but what? Declaring inherit/using Umbraco.Web.WebApi.UmbracoApiController also generates an error.

  • Alex Skrypnyk 6133 posts 23952 karma points MVP 7x admin c-trib
    Jun 26, 2017 @ 15:36
    Alex Skrypnyk
    0

    Hi James

    Add please one more using to the top of the .cs file:

    using Umbraco.Web.WebApi;
    

    A tutorial on how to create an API controller - it's hard question because it's so flexible and you need just use basic Umbraco knowledge for generating output.

    Are you using Visual Studio?

    Thanks,

    Alex

  • Nik 1599 posts 7179 karma points MVP 6x c-trib
    Jun 26, 2017 @ 14:30
    Nik
    100

    Hi James,

    If your strength lies in the WordPress and php side of things, I would probably say an option would be the RSS feed or an alternative templates approach as opposed to creating an API.

    Option 1 You could then use your WordPress site to call your feed and then download a "content only" view or a partial view for saving into your WordPress site(s).

    Lets say for example you have a "News page", this could have an alternate template that is just an XML list of all the news articles with the last updated date and their guid (so you have a unique reference just in case something changes).

    You could grab this using a php curl script in a Chron job, then iterate around the results and pull out the url for each news article. If any are new or have changed you can then call them and retrieve the copy.


    Option 2 Another alternative is to have the Umbraco site push the updates to the WordPress sites by creating an end point on those sites then use the Publish event in Umbraco to send the updated copy.

  • James Taylor 14 posts 124 karma points
    Jun 26, 2017 @ 15:20
    James Taylor
    0

    Thanks, Nik.

    Option 2 was kind of what I was thinking - in Wordpress I'd just hook into the the save_post action and run a function to push the content to the other website - is there an Umbraco equivalent?

    Option 1 is certainly the "easier" way, but wouldn't expand my understanding of Umbraco...

  • Nik 1599 posts 7179 karma points MVP 6x c-trib
    Jun 26, 2017 @ 15:42
    Nik
    0

    Hi James,

    There is indeed a version of that in Umbraco.

    This link gives you a bit of an example. https://our.umbraco.org/documentation/getting-started/Code/Subscribing-To-Events/

    If you are editing the site using Visual Studio it will make things much easier to create these modifications as you'll get helpful IntelliSense on using statements and other bits.

    Let us know if you need more of a hand or examples with it but that link should start you on the right path :-)

Please Sign in or register to post replies

Write your reply to:

Draft