• slotty7130

    (@slotty7130)


    Hi,

    i have a problem with instantiating variables

    when i use this code in a taxonomy file, then everything works:

    if ($term->name == "Rotwein") {
            if (have_posts()) : while (have_posts()) : the_post();
                echo $this->render('_post'); ?>
                <?php echo $this->render("_pagination", array("type" => "posts")); ?>
                <?php endwhile; ?>
                <?php else : ?>
                <h1 class="title"><?php printf(__("Sorry, but there aren't any posts in the %s category yet.", "warp"), '<span>' . $term->name . '</span>'); ?></h1>
               <?php get_search_form(); ?>
                <?php endif;
    ; ?>

    now i want define the if/while (have_posts()) loop in a function…this function is in a mu-plugins folder in wp-content
    but now i have the problem with $this->render…$this is not instantiated in order to use it in taxonomy file

    so my question:
    how can i make the code useable in my taxonomy file…?

    something like this
    wp-content/mu-plugins/wines.php:

    function funcRedwine()
    {
        if (have_posts()) : while (have_posts()) : the_post();
            echo $this->render('_post');
            echo $this->render("_pagination", array("type" => "posts"));
        endwhile;
        else : ?>
        <h1 class="title"><?php printf(__("Sorry, but there aren't any posts in the %s category yet.", "warp"), '<span>' . $term->name . '</span>'); ?></h1>
        <?php get_search_form();
        endif;
    }
    add_filter('content', 'funcRedwine');
    ?>

    taxonomy-wines.php:

    if ($term->name == "Redwine") {
          funcRedwine();
        } elseif ($term->name == "Whitewine") {
          funcWhitewine();
        }

    any help would be appreciated

    cheers
    slotty

  • The topic ‘instantiating variables’ is closed to new replies.