Support » Plugin: ShortCodes UI » Combining php and html

  • Resolved dinkelgodis


    Hello! Great plugin!

    I want to combine php and html in my shortcode. This is what I have done:

    ?><div id="tjanster">
    <?php $i=1; ?>
    <?php query_posts('category_name=tjanster'); ?>
        <?php if (have_posts()) : while (have_posts()) : the_post();?>
        		<div class="tjanster_post tjanster_nr_<?php echo $i ?>">
                	<?php the_content(); ?>
                <?php $i++; ?>
        <?php endwhile; endif; ?>

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    And it works almost perfectly. The problem is that it goes through the loop twice. The first time it reads the html and the second time it doesnt. What can i do to solve this? 🙂

Viewing 1 replies (of 1 total)
  • Plugin Author Bainternet


    Not use query__posts for starters.

    Its meant to modify the main query which is clearly not the case here.
    And for a better solution you should use a code that returns php and not echo’s it out so try this:

    $html = '<div id="tjanster">';
    $qs = new get_posts(array('category_name'=> 'tjanster'));
    foreach ($qs as $q) {
    	$html .= '<div class="tjanster_post tjanster_nr_'. $i .'">'.$q->post_content.'</div>';
    $html .= '</div>';
    return $html;
Viewing 1 replies (of 1 total)
  • The topic ‘Combining php and html’ is closed to new replies.