We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18913
    • 654 Posts
    I have done searches of both Google and the archives here and don’t really have an answer to this. So ...

    I would like to be able to show Wordpress results on a page within a MODx site. I understand that I need to include wp-blog-headers.php and I did that by putting that on the second line of the site’s index.php.

    My first question is whether or not there’s a better place to do that? I tried adding it in a header chunk, but that didn’t seem to work.

    Next, I created a document that had the template I wanted to use for styling and added The Loop code from the "classic theme" index.php found on the Wordpress install (as outlined here http://moshublog.com/2005/07/05/integrate/2/)

    Initially, I thought I could put all the output into a variable and return that at the end of the snippet. But that didn’t generate the expected results, as it seems some of the WP functions do not really return a string.

    What ended up basically working was this :
    <?php
    if (have_posts()) : while (have_posts()) : the_post();
    the_date('','<h2>','</h2>');
    echo    '<div ';
    post_class();
    echo    ' id="post-' . the_ID() . '"><h3 class="storytitle"><a href="';
    the_permalink();
    echo  '" rel="bookmark">';
    the_title();
    echo    '</a></h3>';
    echo    '	<div class="meta">' .  _e("Filed under:") . the_category(',') . ' —' . the_tags(__('Tags: '), ', ', ' — ') . the_author() . '@' . the_time() . edit_post_link(__('Edit This')) . '</div>';
    echo    '	<div class="storycontent">';
    the_content(__('(more...)'));
    echo  '	</div>';
    echo   '	<div class="feedback">';
    wp_link_pages();
    comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)'));
    echo    '	</div>';
    echo   '</div>';
    
    comments_template(); // Get wp-comments.php template
    endwhile; else:
    echo  '<p>' .  _e('Sorry, no posts matched your criteria.') . '</p>';
    endif;
    ?>
    


    So my second question is : "Is there a better way to implement this code?"

    The third question is pretty much trivia at this point, namely, does anyone know what has happened to the (Japanese?) "Wordpress-Integrator" snippet that one finds referenced in the archives?

    Thanks in advance for sharing any experiences, tips, resources along these lines!
    Matt
      • 18913
      • 654 Posts
      This works a little better, except that the commented out function calls mess things up if included this way...
      <?php
      $output = '';
      if (have_posts()) : while (have_posts()) : the_post();
      $output .= the_date('','<h2>','</h2>');
      $output .=     '<div ';
      //$output .= post_class();
      $output .=    ' id="post-' . get_the_ID() . '">';
      $output .= '<h3 class="storytitle"><a href="' . get_permalink() . '" rel="bookmark">' . get_the_title() . '</a></h3>';
      $cat = '';
      foreach((get_the_category()) as $category) { 
          $cat .= $category->cat_name . ','; 
      }
      //NEED TO DELETE THE LAST COMMA - MATTC
      $output .=     '	<div class="meta">' .  _("Filed under:") . $cat . ' —' . get_the_tags(__('Tags: '), ', ', ' — ') . get_the_author() . '@' . get_the_time() . get_edit_post_link(__('Edit This')) . '</div>';
      $output .=     '	<div class="storycontent">';
      $content = get_the_content();
      $content = apply_filters('the_content', $content);
      $content = str_replace(']]>', ']]>', $content);
      $output .=  $content;
      $output .=   '	</div>';
      $output .=    '	<div class="feedback">';
      $output .= wp_link_pages();
      //$output .= comments_popup_link(__('Comments (0)'), __('Comments (1)'), __('Comments (%)'));
      $output .=     '	</div>';
      $output .=    '</div>';
      
      $output .= comments_template(); // Get wp-comments.php template
      endwhile; else:
      $output .=   '<p>' .  _('Sorry, no posts matched your criteria.') . '</p>';
      endif;
      return $output;
      ?>
      
        • 20413
        • 2,877 Posts
          @hawproductions | http://mrhaw.com/

          Infograph: MODX Advanced Install in 7 steps:
          http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

          Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
          http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
          • 18913
          • 654 Posts
          Hi,
          I had seen the first link, but not the second (searched the archives for "wordpress", which doesn’t appear in the note!). That looks like a nice example of blending MODx and Wordpress visually, so I’ll look into it more. Thanks!
          Matt