0
votes

I am new to Wordpress and have the following problem:

I am working on a website that includes a blog page with news -> it is referred to by the navigation list item "NEWS".

In addition, I have created an additional custom post type with a listing of events. -> it is referred to by the navigation list item: "EVENTS". The page with the event list is based on the file page-events.php. When you click on a event to get a single view, the page that opens is based on single-event.php.

So basically I have two single.php-files, one for my news, the other one for my events.

MY PROBLEM: When you click on an event for a single view or you click on an event category and leave the file page-events.php, then in the navigation bar the "EVENTS" list item is no longer selected as the current page item, BUT the "NEWS" list item.

Well, the "NEWS" item refers to my main blog page. How can I achieve that the "EVENTS" list item stays selected when I click on an event in my event list?

Here the code of my single-event.php:

<!-- Header -->
<?php get_header();
if ( is_page() ) {
        if($post->post_parent)
            $children = 
            wp_list_pages("title_li=&child_of=".
            $post->post_parent."&echo=0");
        else
            $children =
            wp_list_pages("title_li=&child_of=".
            $post->ID."&echo=0");
        if ($children) {
        echo "<div id='submenu'>";  
        echo "<ul>";
        echo $children;
        echo "</ul>";
        echo "</div>";  
        }
    } else { 
   if ( !function_exists('dynamic_sidebar') || 
   dynamic_sidebar('Sidebar') ) :
   endif;   }
   st_before_content($columns=''); ?>

<!-- Content -->
   <?php if ( have_posts() ) : 
   while ( have_posts() ) : the_post(); 
   $custom_fields = get_post_custom( $post->ID ); ?>
   <h2><?php the_title(); ?></h2>
   <? $date = get_the_term_list( $post->ID, 'date' ); ?>
   <h3><?php echo $date; ?> &nbsp;&nbsp; &bull; &nbsp;&nbsp; <?php echo    
$custom_fields["time"][0]; ?> h</h3>
   <?php
   if ( function_exists('has_post_thumbnail') && 
     has_post_thumbnail() ) {
      the_post_thumbnail();
   } ?>    
   <p><?php the_content(); ?></p>
<?php endwhile; endif; ?>

<!-- Footer -->
<?php
st_after_content();
get_footer();
?>
1
can you post your code please? - Mark
hi mark, sure will do. :) the code of which files are you interested in? - MaxNagler

1 Answers

0
votes

SOLUTION

I found out that this is a general wordpress problem. The "EVENTS" list item cannot be made the current-page-item, but I found a workaround how to manipulate the CSS of the "NEWS" item and to remove its visual "current-page-item look":

  1. Go to the header.php and put a div-box around it with the current custom post type set as the class, like this:

<div class="<?php echo get_post_type( $post ); ?>"> <!-- Navigation bar --> </div>

  1. Now you can manipulate the CSS by adressing the menu item by its ID that you can find out about in the source code (with Google Web Developer, for example):

.events .menu-item-62 { color: #ff0000; }