2012-10-18 14 views
0

這是工作在網站上i'm:http://canal.es/wordpress/高亮(活動)菜單中的文章標題

我的是,如果你去,爲「Pasteleria杜爾塞」的問題(這是一個category.php文件),它顯示了一個左側邊欄,其中顯示了該類別的活動標題,它在中心顯示了一個帖子,並在圖片下方顯示了同一類別帖子的列表。

我沒有找到解決方案來突出顯示當我進入該類別時自動打開的帖子標題。這是我在category.php文件上使用的代碼:

<!-- Highlight menu from current category --> 
    <?php 
     if (is_category()) { 
      $this_category = get_category($cat); 
      } 
     if($this_category->category_parent) 
      $this_category = wp_list_categories('orderby=id&title_li=&child_of='.$this_category->category_parent."&echo=0"); else 
      $this_category = wp_list_categories('orderby=id&title_li=&child_of='.$this_category->cat_ID."&echo=0"); 
     if ($this_category) { ?> 
     <ul class="sub-menu"> 
      <?php echo $this_category; ?> 
     </ul> 
    <?php } ?> 



    <div class="producto_column">   
     <?php /* Start the Loop */ ?> 
     <?php while (have_posts()) : the_post(); ?> 

      <div class="producto_image"> 
       <img src="<?php the_field('imagen_producto'); ?>" alt=""/> 
      </div> 

       <div class="share_item"> 
        <a class="minimal" id="premium"> 
         <img src="<?php bloginfo('template_directory') ?>/images/share.png" alt="share"> 
        </a> 
        <a class="maillink" href="http://canal.local/?page_id=220"> 
         <img src="<?php bloginfo('template_directory') ?>/images/email.png" alt="email"> 
        </a> 
       </div> 

      <?php get_template_part('content', get_post_format()); ?> 

     <?php endwhile; ?> 

    <!-- Post list from current category --> 
    <ul id="submenu_productos" class="clearfix"> 
     <?php 
      $IDOutsideLoop = $post->ID; 
      while(have_posts()) { 
       the_post(); 
       foreach((get_the_category()) as $category) 
        $my_query = new WP_Query('category_name=' . $category->category_nicename . '&orderby=title&order=asc&showposts=100'); 
       if($my_query) { 
        while ($my_query->have_posts()) { 
         $my_query->the_post(); ?> 
       <li<?php print (is_single() && $IDOutsideLoop == $post->ID) ? ' class="test"' : ''; ?>> 
        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> | 
       </li> 
     <?php 
       } 
      } 
     } 
     ?> 
    </ul> 

我該如何激活當前打開類別頁面時顯示的帖子標題?

回答

0

嘗試使用此解決方案:

<ul> 

    <?php 
     $lastposts = get_posts('numberposts=5&orderby=rand&cat=-52'); 
     foreach($lastposts as $post) : 
     setup_postdata($post); ?> 

     <li<?php if ($post->ID == $wp_query->post->ID) { echo ' class="current"'; } else {} ?>> 

      <a href="<?php the_permalink() ?>"><?php the_title(); ?></a> 

     </li> 

    <?php endforeach; ?> 

</ul> 
+0

它doesn't似乎工作。不管怎樣,謝謝你。它看起來像這個目標的路徑,這是目前的類別路徑,而不是郵件的路徑... –

+0

嘗試新的!這可能是你的 – RDK

+0

hehe不,現在這個隨機顯示所有類別的帖子...看看網站,它不會突出顯示任何東西 –