• Hello,

    I am trying to embed a blog into an existing webpage. I tried this in the following way:

    The existing webpage is implemented using Smarty, a template engine. Since I am trying to give template authors the possibility to embed a blog into whatever template they choose, the only way is to register a function to Smarty, which is then made accessible to the template.

    The bottom line is: A function needs to be passed to Smarty that returns the complete blog.
    However, doing something like this:

    ———-
    define(‘WP_USE_THEMES’, true);

    function show_blog() {
    require(‘wordpress/wp-blog-header.php’);
    }

    $s = &new Smarty();
    $s->register_function(“blog”, “show_blog”);
    ———-

    produces the following error message:

    —————–
    Fatal error: Call to a member function on a non-object in /home/www/wordpress/wp-includes/functions.php
    —————–

    When calling require() in global scope it works, but this will obviously not integrate with the template engine. Is there an easy way to achive something similar?

    (note for the Smarty-experienced folks:
    “{php}require(‘wordpress/wp-blog-header.php’);{/php}”
    produces the same problem; the snipped is called from within a function)

    Thanks,
    -Samuel

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter knipknap

    (@knipknap)

    Alright, I worked out a solution:


    function _show_blog() {
    global $cache_userdata,
    $wpdb,
    $wp_query,
    $wp_rewrite,
    $post,
    $category_cache,
    $request,
    $posts_per_page,
    $wpdb,
    $max_num_pages;
    define('WP_USE_THEMES', true);
    require('wordpress/wp-blog-header.php');
    }

    Works for me with WP1.5. Now, someone please sack the WP developers for horrible abuse of global variables.

    Now, someone please sack the WP developers for horrible abuse of global variables.

    Can’t, because we didn’t really hire them. They just wandered in one day and started coding. For free.

    I’m glad you figured out your problem, because I was stumped by it.

    A multi author blogging solution using the Smarty template system…my friend, you are reinventing the wheel.

    https://mu.www.ads-software.com/

    I saw the wordpress mu link and that would definitely do the trick, but I already started with the regular version of wordpress. Do you know if I can safely upgrade from wordpress 1.5 to wordpressmu and keep my posts and all of the coding I worked so hard to create in tact? I dont want to have to do all of that work again and if I could just use a simple echo function that would work (ie, allow me to include my posts on a separate webpage that was already created and resides outside the blog folder and main page), that would be great. I was thinking something more along the lines of this code I saw in another post:

    <?php define(‘WP_USE_THEMES’, false);
    require(‘./wp-blog-header.php’);
    get_header();?>
    <div id=”content” class=”narrowcolumn”><h1 style=”color:#000;”>Welcome to my site</h1>
    Hello and welcome to my site. You can go to my web page about how to improve your
    shoots with your digital camera; or you can go to my blog
    <h2>Lastest posts in my blog:</h2><?php
    # Here starts Mini Loop trick: You can use this code, but _at your own risk_
    # If you want to improve this code, you’re welcome ??
    $how_many=7; //How many posts do you want to show ?>
    <ul class=”whats-new”>
    <?
    $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 (”

    • %s
    • “, $np->ID,$np>post_title);
      }?></div>
      <?php get_sidebar(); get_footer(); ?>

      I tried it but also produces ‘Fatal error: Call to a member function on a non-object’ output error. I think there may be something wrong in the syntax but seems like it should work otherwise.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Calling wordpress from within a function’ is closed to new replies.