We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23323
    • 12 Posts
    In finally got off my butt and have decided to do actually do some website work that doesn’t involve being brain-dead and using drupal. So here I am switching to MODx (which I love). Heres my issue:

    I’m currently using Wordpress to blog. I’ve looked at switching to MODx for that as well, but it just doesn’t have the polish for this specific purpose that Wordpress does. So I thought I would use "The Loop" in Wordpress to display blog posts and information from MODx pages. I created a real file test.php and put
    <?php 
    define('WP_USE_THEMES', false);
    require('./wordpress/wp-blog-header.php');
    //get_header();
    ?>
    <?php
    require_once("./wordpress/wp-config.php");  ?>
    <div id="content">
    <?php query_posts('cat=1&showposts=1'); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div class="post">
    <h3 class="posttitle" id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    <div class="details"><div class="inside">Written by <?php the_author_posts_link() ?> on <?php the_time('d.m.Y');?> |
    <?php the_category(', ') ?> <?php edit_post_link('Edit this', ' - ', ''); ?></div></div>			
    <div class="postcontent">
    <?php the_excerpt_reloaded(500, '<p><a><ul><ol><li><img><br /><blockquote>', 'content', FALSE, '', FALSE, 1, TRUE); ?>
    <?php 
    $distract = get_post_meta($post->ID, "Current Distraction", true);
    if ($distract) {
    echo "<b>Current Distraction:</b> " . $distract;
    }
    ?>
    </div>
    <div class="details"><div class="inside"><?php comments_popup_link('No Posts', '1 Post', '% Posts'); ?> so far | <a href="<?php the_permalink() ?>">There's More »</a></div></div>																		
    <!--
    <?php trackback_rdf(); ?>
    -->
    </div>
    <?php comments_template();  ?>
    <?php endwhile; else: ?>
    <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
    <?php endif; ?>											
    </div>


    and I get 1 post displayed.
    Than I put the same code in a snippet and I get an error:
    Fatal error: Call to a member function get_row() on a non-object in ./wordpress/wp-includes/functions.php on line 281

    I figured out that I can put
    define('WP_USE_THEMES', false);
    require('./flog/wp-blog-header.php');

    in the at the top of the MODx index.php file, but then I get different errors (I’ve gotten some functions to work, but others do not function)

    Does anyone have any experience with this? Also, is there a way to execute "clean" php within MODx (Im assuming we’re seeing some issue with the MODx environment effecting the Wordpress Loop)? Is there a good way to get debug information about why some Wordpress are functioning, but others aren’t?

    TIA
      • 22303 MODX Staff
      • 10,725 Posts
      I started down this road with my first MODx site and quickly ran into the same issues. I finally gave up and just left WordPress alone, running alongside MODx with a common CSS and replicated theme/template, because I didn’t want to have to recode part of WP to make it work. I may give this a try again soon though, as I still have the need myself.
        • 23323
        • 12 Posts
        I saw a previous post by you that sounded like you were headed for the same issue as me. It works just fine in a vanilla php file, so I’m thinking there are MODx environment issues going on here. I’ve gotten it to work partially, but when I try the suggested "Mini Loop code" as seen on http://codex.wordpress.org/Creating_a_Static_Front_Page, I get an error about get_results() on a non-object (suggesting to me $wpdb is not being setup properly with the required wp-config.php). But I am having trouble getting any specific information, paritally because I dont know how to test for it (because I need to look at wordpress’ documentation a little more). Even assuming that that is the problem; why is it a problem and how would I go about fixing it. I’d like to use the wordpress functionality, but I may just roll my own if this becomes too much of a headache.
          • 22303 MODX Staff
          • 10,725 Posts
          I believe all of the issues involve the paths used within wordpress not liking the way MODx is always assuming the root path of MODx when running. In other words, because WordPress expects to be executing from the root path of the WP installation, and not the root path of the MODx installation. I haven’t found an acceptable solution for this, but, I am planning on writing some WordPress plugins at some point that can render MODx components within WP. Some systems are better integrated in this way, that pulled directly into MODx, and with this capability, MODx will become a much richer web application integration platform.

          Quote from: physorg at Jun 01, 2006, 10:55 AM

          I saw a previous post by you that sounded like you were headed for the same issue as me. It works just fine in a vanilla php file, so I’m thinking there are MODx environment issues going on here. I’ve gotten it to work partially, but when I try the suggested "Mini Loop code" as seen on http://codex.wordpress.org/Creating_a_Static_Front_Page, I get an error about get_results() on a non-object (suggesting to me $wpdb is not being setup properly with the required wp-config.php). But I am having trouble getting any specific information, paritally because I dont know how to test for it (because I need to look at wordpress’ documentation a little more). Even assuming that that is the problem; why is it a problem and how would I go about fixing it. I’d like to use the wordpress functionality, but I may just roll my own if this becomes too much of a headache.
            • 23323
            • 12 Posts
            I wonder if there is a variable or definition that you could set before and after the executed code to ensure proper execution.
              • 23323
              • 12 Posts
              Looking through the Wordpress documentation it seems like you may have to declare $wpdb as global. I tried
              $how_many=5; 
              require("./flog/wp-config.php");
              global $wpdb;
              $news=$wpdb->get_results('SELECT `ID`,`post_title` FROM ' . $wpdb->posts . 'WHERE `post_status`= "publish" ORDER BY 'ID' DESC LIMIT '.$how_many);
              foreach($news as $np){
              printf ('<li><a href="./wordpress/index.php?p=%s">%s</a></li>', $np->ID,$np->post_title);
              }


              but I’m not seeing any different results, still getting
              Parse error: syntax error, unexpected T_STRING in ./manager/includes/document.parser.class.inc.php(705) : eval()'d code on line 7


              so... it sounds like get_results() might be messed up? Does MODx use a function called get_results()?

                • 23323
                • 12 Posts
                Well ok.
                Parse error: syntax error, unexpected T_STRING in ./manager/includes/document.parser.class.inc.php(705) : eval()'d code on line 7

                The above error is being thrown from MODx. It’s evaluating my code an then throwing an error because it doesnt like that I used a string (even though a string is what belongs there). Is there a way to prevent this code from being evaluated by MODx (or fix it the parser)?
                  • 10487 MODX Staff
                  • 1,535 Posts
                  Hi physorg,

                  I was just looking at the code snippet you posted and did notice that the query call may perhaps be causing a problem.
                  $news=$wpdb->get_results('SELECT `ID`,`post_title` FROM ' . $wpdb->posts . 'WHERE `post_status`= "publish" ORDER BY 'ID' DESC LIMIT '.$how_many);

                  The quotes around ID in the ORDER BY statement look they need escaping:
                  ... ORDER BY \'ID\' ...
                  Just a thought,

                  Garry
                    Garry Nutting
                    Senior Developer
                    MODX, LLC

                    Email: [email protected]
                    Twitter: @garryn
                    Web: modx.com
                    • 23323
                    • 12 Posts
                    aaahhh

                    <_<
                    >_>

                    ...


                    Im dumb.
                    Ok! So the lesson today children: Dont cut-and-paste other people’s code. That fixed my issue, that and globalizing $wpdb.
                      • 23323
                      • 12 Posts
                      -SO- in conclusion...

                      If you want to add Loop support in MODx you must add the following to the top of your MODx index.php file:
                      define('WP_USE_THEMES', false);
                      require('./flog/wp-blog-header.php');
                      


                      Then in the code of you page you must add:
                      require("./flog/wp-config.php"); 
                      global $wpdb;


                      I have found other things you might need to globalize (such as $post) I guess you will kind of have to feel it out, but this has allowed me to use The Loop within MODx.