2012-08-02 73 views
0

我使用以下代碼來顯示發生後的信息。但我有一個問題。 我不想在博客頁面和主頁等特定頁面上顯示發佈信息。條件不工作在wordpress

所以我嘗試了一些方法,但不工作。

其實我剛纔創建的頁面模板.. 頁面blog.php的頁面home.php

remove_action('genesis_before_post_content', 'genesis_post_info'); 
add_action('genesis_before_post_title', 'child_post_info'); 

function child_post_info() { 
    if (!is_page('blog')) { 
    return; 
?> 

    <div class="post-info"> 
     <span class="date published time"> 
      <time class="entry-date" itemprop="startDate" datetime="<?php echo get_the_date('c'); ?>" pubdate><?php echo get_the_date(); ?></time> 
     </span> By 
     <span class="author vcard"> 
      <a class="fn n" href="<?php echo get_the_author_url(get_the_author_meta('ID')); ?>" title="View <?php echo get_the_author(); ?>'s Profile" rel="author me"><?php the_author_meta('display_name'); ?></a> 
     </span> 
     <span class="post-comments">&middot; <a href="<?php the_permalink() ?>#comments"><?php comments_number('Leave a Comment', '1 Comment', '% Comments'); ?></a></span> 
     <?php // if the post has been modified, display the modified date 
     $published = get_the_date('F j, Y'); 
     $modified = the_modified_date('F j, Y', '', '', FALSE); 
     $published_compare = get_the_date('Y-m-d'); 
     $modified_compare = the_modified_date('Y-m-d', '', '', FALSE); 
      if ($published_compare < $modified_compare) { 
       echo '<span class="updated"><em>&middot; (Updated: ' . $modified . ')</em></span>'; 
      } ?> 
    </div> 
<?php } 
} 

,請給我一些想法我怎麼能解決這個問題。

NOW:

我創建了一個新的文件元postinfo.php

並保存

<div class="post-info"> 
... 
</div> 

和functions.php文件..

remove_action('genesis_before_post_content', 'genesis_post_info'); 
add_action('genesis_before_post_title', 'child_post_info'); 

function child_post_info() { 
    if (!is_home() && !is_page(array('blog', 'inspiring quotes'))) { 
     get_template_part('meta', 'postinfo'); 
    }; 
} 

上面的代碼正在與博客頁面和主頁,但不能與「鼓舞人心的報價頁面雖然我已經嘗試

if (!is_home() && !is_page('blog') && !is_page('inspiring quotes')) { 

,但沒有工作..做u有什麼想法?

+0

嘗試'鼓舞人心的報價' – 2012-08-03 04:10:24

回答

1

要隱藏的特定頁面模板給定函數使用is_page()函數像這樣(隱藏頁面與約塞):

<?php 
if (!is_page('about')) { 
// This function will not run on the homepage 
}; 
?> 

要隱藏你的主頁的東西使用is_Home

<?php 
if (!is_home()) { 
// This function will not run on the homepage 
}; 
?> 

見:http://codex.wordpress.org/Function_Reference/is_pagehttp://codex.wordpress.org/Function_Reference/is_home

編輯:這不會是一個由ADD_ACTION但我調用的函數nstead能夠正確寫入您的模板,其中以往任何時候都應該顯示,如:

<?php 
if (!is_home()) { 
    <div class="post-info"> 
    <span class="date published time"> 
    // ... the rest of this display template. 
    }; 
    ?> 

如果打算在多個模板中使用,你可以把它移到一個單獨的文件,並使用類似:

<?php 
if (!is_home()) { 
    get_template_part('postinfo'); 
    }; 
    ?> 
+0

不工作夥伴..我有一個博客頁面的問題。我試過is_page('博客')..但它沒有奏效。 – Muzzy 2012-08-02 21:32:18

+0

我已經嘗試了上面的代碼...但它不工作。 – Muzzy 2012-08-02 21:41:59

+0

對不起,我不是很清楚我的建議。我編輯我的答案 – 2012-08-02 21:46:34