We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21314
    • 4 Posts
    hi everyone,

    i am looking into wp integration for my modx site. the blog will be located at www.mydomain.com/blog but i need a lot of wp content for my home page.

    the end result is something like : http://www.pentictonvees.ca/ where a ’news slider’ shows the 5 most recent wp posts and beneath that a ’previous headlines’ section shows posts 6 through to 10.

    i guess i could make each of the news sliders a seperate chunk to update whenever the client makes new posts and the previous headlines also a chunk to update manually but obviously an automatic solution is prefered.

    after some research i have come accross the following resources:

    http://www.corvidworks.com/articles/wordpress-content-on-other-pages
    This method seems very promissing and the only concern for me is how much slowdown the homepage will take due to loading the wp api through ’wp-blog-header.php’.

    http://www.corvidworks.com/articles/easy-feed-reading-with-simplepie
    Just a concern about how well the posts can be styled (titles, content, include the post thumbnails, etc)

    http://www.jamischarles.com/blog/how-to-add-recent-wordpress-posts-on-an-external-html-page/
    will this be faster to load than the wp-blog-header.php aproach? are there any risks disclosing database password service side like this?

    1. Which of these would be the best approach?

    2. Could there be any complications by doing this on a modx site and is there a better way?

    i have read other posters on this forum trying to achieve this so i hope this benefits some other members of this community.

    thanks in advance
      • 7231
      • 4,205 Posts
      I would use the simplePie method (or maybe use FeedX snippet). Load the WP blog content from a feed or xml file.
      It is all in the database so you could also query the data directly from the blog database with a custom snippet or plugin.
        [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

        Something is happening here, but you don't know what it is.
        Do you, Mr. Jones? - [bob dylan]
        • 24741
        • 3 Posts
        Although it may not be the best solution, I worked this one out: http://hiredgunscreative.com/integrating-a-wordpress-blogroll-into-a-modx-sidebar/

        It can be seen in action at http://allianceforarts.com.

        I liked it because it did not necessitate the execution of a bunch of WordPress overhead (and possible conflicts). On the other hand, depending on PHP’s handling of the RSS extraction, this may create it’s own overhead. In the end, it worked.

        My issue now is how to supply the dynamic menus and submenus from the navigation in MODx into the WordPress blog at http://allianceforarts.com/blog. The only reason I post this question here is because there is a lot of similarity between the OP’s project and mine, and the OP might also be looking for a solution to this issue.
          • 10449
          • 956 Posts
          Should be relatively easy. Create a new doc (with no template assigned to it, i.e. blank) with a Wayfinder call, publish it, but untick both "show in menu" + "searchable?".

          In your WP template, simply include() this doc via PHP. Maybe you’ll have to adjust link-paths, depending on your structure.
            • 22770
            • 285 Posts
            PatrickSamphire Reply #5, 15 years ago
            I would suggest using the custom snippet method and query the WP part of the database directly. I would have thought that would be the fastest and most flexible method, and it uses fairly rudimentary PHP, so it shouldn’t be too challenging.
              • 24741
              • 3 Posts
              Quote from: ganeshXL at Apr 15, 2009, 08:28 PM

              Should be relatively easy. Create a new doc (with no template assigned to it, i.e. blank) with a Wayfinder call, publish it, but untick both "show in menu" + "searchable?".

              In your WP template, simply include() this doc via PHP. Maybe you’ll have to adjust link-paths, depending on your structure.

              I tried this and now have a great page with the menu on it (perfect), but I cannot seem to include() or include_once() or request() or even fopen/fread the file in the WordPress page.

              Here is the MODx page: http://allianceforarts.com/wordpress.html
              And here is the code I call at http://allianceforarts.com/blog/?page_id=2
                  <div id="menu"> 
                  	<div id="menu-inner"> 
              <?php
              
              	include('http://allianceforarts.com/wordpress.html');
              
              ?>
                      </div>
              	</div>


              Not exactly super sophisticated, but I can’t figure out it is a MODx, WordPress, or server issue as to why the include won’t work. Any thought?
                • 7231
                • 4,205 Posts
                Dont think that you can use a url path for the include. Have you seen this post: http://modxcms.com/forums/index.php/topic,34880.0/topicseen.html
                  [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

                  Something is happening here, but you don&#39;t know what it is.
                  Do you, Mr. Jones? - [bob dylan]
                  • 24741
                  • 3 Posts
                  I had to enable allow_url_include in the php.ini to get this working. It’s running, but a better solution would have been to enable the same option in the .htaccess file instead (which I couldn’t for some reason).
                    • 10449
                    • 956 Posts
                    You could also use the CURL PHP library (if it’s enabled on your server).
                    http://ch.php.net/manual/en/curl.examples-basic.php
                      • 14044
                      • 1 Posts
                      I was wondering the same thing, so I wrote this snippet and called it from my home page. This should be much faster than the Feedburner solution I was using. I don’t know much about security though, so I can’t say that accessing the DB directly is the safest thing. Replace "databaseserver","database","password" on lines 2 & 3 with your connection info.

                      <?php
                      mysql_connect("databaseserver","database","password") or die("error making database connection"); 
                      mysql_select_db("database") or die("error connecting to database"); 
                      
                      $rs=mysql_query("select * from wp_posts order by post_date desc LIMIT 1");
                      $num = mysql_num_rows($rs); 
                      
                      while($row = mysql_fetch_array( $rs )) {
                      	echo "<h1><a href='".$row['guid']."'>". $row['post_title']."</a></h1>";
                      	echo "<h2>".date('m/d/y',strtotime($row['post_date']))."</h2>";
                      	echo "<div id='blogPostContent'>".$row['post_content']."</div>";
                      }
                      ?>
                      


                      Obviously you can format the code and class as you need for your own site.

                      Correction: apparently the guid field changes when you autosave, so that isn’t a good link to use. I’m sure there is a permalink field somewhere in the database but I’ve run out of time for the day so I just hardcoded in "/blog" which takes me to my most recent post anyway. This should get you halfway there.