2016-01-20 71 views
0

我試圖給當前頁面添加一個用戶在Wordpress中的頁面。類沒有被添加到當前頁面? (要突出顯示活動頁面)

到目前爲止,我有下面的代碼,但它不起作用有沒有人知道爲什麼?

<?php while (have_posts()) : the_post(); ?> 
    <a href="<?php echo get_the_permalink(); ?>" title="<?php echo the_title(); ?>"> 
    <div id="grid-icon" class="icon-news<?php if (is_page($post->ID)) { 
    echo "page-active "; } else {} ?> col-xs-12 col-md-4"> 
    <p><?php echo get_post_meta($post->ID, 'wpcf-short-title', true); ?></p> 
    </div> </a> 
    <?php endwhile;?> 
+0

回顧: - http://stackoverflow.com/a/34897335/2667307 –

回答

0

望着這行:

<div id="grid-icon" class="icon-news<?php if (is_page($post->ID)) { 
    echo "page-active "; } else {} ?> col-xs-12 col-md-4"> 

沒有類icon-newspage-active之間的空間。嘗試改變echo命令:

echo " page-active "; //note the space between `"` and `page-active` 

這也被刪節到:

<div id="grid-icon" 
    class="icon-news<?php echo is_page($post->ID) ? " page-active " : null ?> col-xs-12 col-md-4"> 
0

當您使用PHP代碼在那個時候,你必須之前最初添加一個空格添加類類。

echo "page-active "; } else {} ?> col-xs-12 col-md-4"> 

線將

echo " page-active "; } else {} ?> col-xs-12 col-md-4"> 
+0

@shaun任何更新? –

相關問題