Function declaration doesn´t run

Hi everybody,

I’m customizing a wordpress template, I am implementing tabs.

I have the tabs href=“tabs-1” href=“tabs-2” href=“tabs-3” displaying correctly dynamically.
Now I’m creating a function so that content of those tabs has the id=“tabs-1” id=“tabs-2” id=“tabs-3
The idea is that
<a href="tabs-1"> tabs 1</a>
displays
<div id="tabs-1">content tab 1</div>

<a href="tabs-2"> tabs 2</a>
displays
<div id="tabs-2">content tab 2</div>

Here is my function fuckit(). Problem is that is doesn´t run. I mean, in the front end the code inspector show id="tabs-" instead of displaying id="tabs-1"

<?php while( $get_featured_pages->have_posts() ):$get_featured_pages->the_post(); ; ?>
                         
<?php
        $output = '';
         $himalayas_designation = get_post_meta( $post->ID, 'himalayas_designation', true );
                                
         function fuckit() {
               $init_count = 1;
                do {
                    echo $init_count;
                    $init_count++;
                }  
                while($init_count <= 3);
         };

      $output = '<div class="team-content" id="tabs-' . fuckit() . '">' . '<p>' . get_the_excerpt() . '</p></div>';
    echo $output;
    $count++;
 ?>
<?php endwhile;
 // Reset Post Data
 wp_reset_query(); ?>

In the front end it show:

Thank you in advance.

Hi clemencelc, welcome to the forum

What you’re seeing is because you have echo inside the function.
Try putting $init_count where you call the function instead.

It doesn’t work either…

Thank’s though.

Did you forget to call the function on a separate line (eg. after the function) ?

I declare it in the $output:

$output = '<div class="team-content" id="tabs-' . fuckit( ) . '">' . '<p>' . get_the_excerpt() . '</p></div>';

What you are calling “declare” I call “calling the function”.

You could try having the function return the value instead of having the echo inside it. eg.

function fuckit() {
  $init_count = 1;
    do {
//      echo $init_count;
      $init_count++;
     }  
    while($init_count <= 3);
  return $init_count;
};

Ok, thank’s. sorry.

I did the changes and it still doesn´t work.

I don’t kmow exactly what you mean by “doesn’t work”.

This works for me.

<?php
error_reporting(E_ALL);
ini_set('display_errors', 'true');

$output = "";
function simple() {
  global $reply;
  $reply = "Hey, Forrest";
  return "Hey there";
}

$output .= "<p>" . simple() . " Bubba</p>";
$output .= "<p>" . $reply . "</p>";
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>clemencizm</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
<h1>clemencizm</h1>
<?php echo $output; ?>
</body>
</html>

Try adding at the beginning of the function:

echo '<pre>';
<?php debug_print_backtrace(); ?>
echo '</pre>';

It will tell you if the function is being run/hit and what called it

Hi guys,

thank you for you answers.
That allows me to learn meanwhile.

I am now able to increase the number of the id of the div which content the excerpt:

<?php while( $get_featured_pages->have_posts() ):$get_featured_pages->the_post();?>

                         <?php
                            $bam = 0;
                            while($bam <= 3) {
                              $bam;
                              $bam++;
                            
                       
                             $output = '';
                             $himalayas_designation = get_post_meta( $post->ID, 'himalayas_designation', true );
     
                                 $output .= '<div class="team-content" id="tabs_'.$bam.'">' . '<p>' . get_the_excerpt() . '</p></div>'; 
      
                        echo $output; 
   } ?>  
                         <?php endwhile;
                    
                         // Reset Post Data
                         wp_reset_query(); ?>

The problem is that I only what to increase the id="tabs_’ but is also print each excerpt 4 times each…

I’ve spend all my Sunday afternoon in trying to solve that, but I get stucked.

If someone can explane to me where I did something wrong please.

Thank you very much.

I’ve got the solución:

<?php 
         $panel_id = 0;
          while( $get_featured_pages->have_posts() ):$get_featured_pages->the_post();
 ?>

       <div class="tab-pane fade<?php if ( $get_featured_pages->current_post == 0 ): ?> in active<?php endif; ?>" id="tabs-<?php echo $panel_id; ?>">
            <?php
                    $output = '';
                    $himalayas_designation = get_post_meta( $post->ID, 'himalayas_designation', true ); 

                    $output .= '<p>' . get_the_excerpt() . '</p>';
                    echo $output;
               ?>
        </div>
                            
        <?php $panel_id++;
              endwhile;
                      
            // Reset Post Data
             wp_reset_query(); 
        ?>

I haven´t linked the jQuery UI for tabs, but the dev is ok, check it out:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.