You’re incrementing $count
but I see you’re referencing $counter
. Not sure if those are different but here is a version that uses the same variable in all those places.
$counter = 0; //Hier ist der Count-Begin-Foreach
foreach ( $bookmarks as $bookmark ) :
if ( get_post_status( $bookmark->post_id ) !== 'publish' ) {
continue;
}
// moving below the if statement
$counter ++; //Hier ist der Count-Inner-Foreach
$has_bookmark = true;
?>
<tr>
<td width="50%">
<?php echo $counter ?>
<?php echo '<a href="' . get_permalink( $bookmark->post_id ) . '">' . get_the_title( $bookmark->post_id ) . '</a>'; ?>
<ul class="job-manager-bookmark-actions">
<?php
$actions = apply_filters( 'job_manager_bookmark_actions', array (
'delete' => array (
'label' => __( 'Delete', 'wp-job-manager-bookmarks' ),
'url' => wp_nonce_url( add_query_arg( 'remove_bookmark', $bookmark->post_id ), 'remove_bookmark' ),
),
), $bookmark );
foreach ( $actions as $action => $value ) {
echo '<li><a href="' . esc_url( $value[ 'url' ] ) . '" class="job-manager-bookmark-action-' . $action . '">' . $value[ 'label' ] . '</a></li>';
}
?>
</ul>
</td>
<td width="50%">
<?php echo wpautop( wp_kses_post( $bookmark->bookmark_note ) ); ?>
</td>
</tr>
<?php endforeach; ?>
<?php print "Sie haben " . $counter . " Lesezeichen gesetzt."; //Hier ist der Count-Output?>
If you want to get the count, you might as well make a function to do just that. Then call it directly. I have no idea where $bookmarks
is coming from so you’ll have to figure that one out.
function get_number_of_bookmarks( $bookmarks = array () ) {
$counter = 0;
foreach ( $bookmarks as $bookmark ) :
if ( get_post_status( $bookmark->post_id ) !== 'publish' ) {
continue;
}
$counter ++;
endforeach;
return $counter;
}
?>
<div class="primary nav-menu">
<?php
// do your menu
echo primary_nav_menu();
// Example with an empty array, but this should be your bookmarks array
$bookmarks_array = array();
// echo the count
echo get_number_of_bookmarks( $bookmarks_array );
?>
</div>