Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I"m trying to replace the string "Something Nice will show up here" in the block of codes below with WordPress loop but it doesn't seem to be working. I'd like when Link1 is clicked on, let the post with the ID "intro-paragraphs" show. Any ideas on how to do that properly?

<?php

   $longString = "Something Nice will show up here";

    $link=$_GET['link'];
    if ($link == '1'){
         echo $longString;
    }
    if ($link == '2'){
        include 'page2.php';
    }
    if ($link == '3'){
        include 'page3.php';
    }
    if ($link == '4'){
        include 'page4.php';
    }
        ?>

Like this

<?php

$longString = "<?php


$query = new WP_Query('category_name=intro-paragraphs');


if($query->have_posts()) : while($query->have_posts()) : $query->the_post(); 


?>
    <div class="mid-box">
      <h1>
        <?php the_title(); ?>
      </h1>
      <?php echo excerpt(40); ?><br/>
      <a href="<?php echo get_permalink(); ?>">&raquo; read more...</a> </div>
    <!-- End Mid-Box -->
    <?php endwhile; ?>
    <?php endif; ?>";
share|improve this question
1  
sorry, but I have no clue what you're trying to accomplish here. could you perhaps explain in more detail what end result you're trying to achieve? –  Milo Apr 9 '13 at 17:00
    
I'd like when Link1 is clicked on, let a satin post show. –  Dz.slick Apr 9 '13 at 17:09
    
What is a "satin post"? –  vancoder Apr 9 '13 at 18:10
    
Err... Are you trying to double parse some PHP code? Is that even possible? Why would you want to do this (iff it's possible, that is)? I think, what you want to do, is either use a function that is generating your desired output, or just perform the specific actions under certain conditions. But anyway, as Milo and vancoder said, your question really needs some rewording as it is fairly unclear. –  t f Apr 9 '13 at 18:22
add comment

1 Answer

up vote 0 down vote accepted

You can't execute PHP code from within a string.

You can however define a function that executes code and call that function within your if clauses.

function dz_slick_longstring() {
    $query = new WP_Query('category_name=intro-paragraphs');

    if($query->have_posts()) : while($query->have_posts()) : $query->the_post();
    ?>
        <div class="mid-box">
          <h1><?php the_title(); ?></h1>
          <?php echo excerpt(40); ?><br/>
          <a href="<?php echo get_permalink(); ?>">&raquo; read more...</a>
        </div>
    <!-- End Mid-Box -->
    <?php endwhile; ?>
    <?php endif; ?>
<?php
}

Then instead of doing this:

if ($link == '1'){
         echo $longString;
    }

Do This:

if ($link == '1'){
        dz_slick_longstring();
    }
share|improve this answer
    
Chris thank you so much for taking your time to understand my question. –  Dz.slick Apr 9 '13 at 18:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.