0

Im trying to mark as active a page of a queried menu --> (I found the answer)

function render_main_menu(){
$args = array(
    'post_type'     => 'a_cpt',
    'tax_query' => array(
        array(
            'taxonomy'  => 'your_tax',
            'field'     => 'slug',
            'terms'     => 'your_term',
        ),
    ),
);
$loop = new WP_Query($args);

$thetitle = strtolower(get_the_title());
$thetitle = preg_replace("/[\s]/", "-", $thetitle);

while($loop->have_posts()) : $loop->the_post();

    //here the solution--> 
    //marks as bold only the current post -->
    if ( $thetitle == current_post_slug()  ) : ?>

        <div style="font-weight: bold;">

    <?php else : ?>

        <div>

    <?php endif;

    echo '<a href="'.get_permalink().'">'.get_the_title().'</a>'; ?>

        </div>

<?php endwhile; 
wp_reset_postdata();

add_action( 'genesis_after_header', 'render_main_menu', 15 );

function current_post_slug() {
    global $post;
    $post_slug=$post->post_name;
    if ( $post_slug && ! is_wp_error( $terms ) ) {
        return $post_slug;
    }
}

thanks

1
  • You should post your solution as an answer, instead of an edit. It's OK to answer your own question, and you can accept it after 48 hours, so the question will not remain open and unanswered.
    – Gabriel
    Nov 6, 2015 at 13:52

1 Answer 1

0

The code above is correct and includes the answer. I've added a function with a genesis hook to enwrap it so it should just work with copy-past.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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