Skip to content

Commit

Permalink
learn.jquery.com: Fix PHP warning when empty search results
Browse files Browse the repository at this point in the history
Previously, the sidebar logic was trying to mark pages as active
based on the last result, because that's what the $post variable
will be set to from the main loop (have_posts/the_post) in e.g.
the search.php or other theme file.

Weird as that might be, where it goes wrong is when there is no
$post variable, e.g. on a 404, empty category, or empty search
results page.

Fixes jquery/infrastructure-puppet#31.
  • Loading branch information
Krinkle committed Sep 13, 2023
1 parent a6d9ea8 commit f25da6c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions themes/learn.jquery.com/sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<ul>
<?php $chapters = learn_chapter_listing(); ?>
<?php while ( $chapters->have_posts() ) : $chapters->the_post(); ?>
<?php $is_active = ($active_post->ID == $chapters->post->ID) || ($active_post->post_parent == $chapters->post->ID); ?>
<?php $is_active = $active_post && ($active_post->ID == $chapters->post->ID || $active_post->post_parent == $chapters->post->ID); ?>
<li <?php if ($is_active) { echo "class='active'"; } ?>>
<a href="<?php the_permalink(); ?>">
<?php if ( get_post_meta( $post->ID, "icon" ) ) : ?>
Expand All @@ -32,7 +32,7 @@
<ul class="sub-chapter">
<?php while ( $sub_chapters->have_posts() ) : $sub_chapters->the_post(); ?>
<?php if ( has_children( $post ) ) { ?>
<?php $is_active = ($active_post->ID == $sub_chapters->post->ID) || ($active_post->post_parent == $sub_chapters->post->ID); ?>
<?php $is_active = $active_post && ($active_post->ID == $sub_chapters->post->ID || $active_post->post_parent == $sub_chapters->post->ID); ?>
<li <?php if ($is_active) { echo "class='active'"; } ?>>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
Expand Down

0 comments on commit f25da6c

Please sign in to comment.