[英]Limit add_action to default post archive only
我使用 woocommerce 的店面主題。 為了自定義我的博客頁面,我通過一個操作刪除了“storefront_post_content”,並添加了我的自定義 function。
問題是 <?php the_title() 現在也顯示在我創建的自定義帖子類型上。
如何僅限制博客頁面的 remove_action 和 add_action。 我使用了 static 頁面來顯示新聞。
add_action( 'init', 'remove_storefront_actions' );
function remove_storefront_actions() {
remove_action( 'storefront_loop_post', 'storefront_post_taxonomy', 40 );
remove_action( 'storefront_post_header_before', 'storefront_post_meta', 10 );
remove_action( 'storefront_loop_post', 'storefront_post_header', 10 );
remove_action( 'storefront_loop_post', 'storefront_post_content', 30 );
add_action( 'storefront_loop_post', 'jk_custom_storefront_post_content', 30 );
}
function jk_custom_storefront_post_content() {
?>
<div class="entry-content" itemprop="articleBody">
<div class="grid grid-21 grid-news">
<div class="box txt">
<h3><?php the_title() ?></h3>
<?php the_excerpt(); ?>
<?php
echo '<p><a class="btn-alt" href="'.get_permalink().'">Read More</a></p>'; ?>
</div>
<div class="box img">
<?php
if ( has_post_thumbnail() ) {
the_post_thumbnail( 'full', array( 'itemprop' => 'image' ) );
}
?>
</div>
</div>
</div>
<?php
}
?>
我試圖將它包裝在 if 語句中,例如:
global $wp_query; if( isset( $wp_query ) && (bool) $wp_query->is_posts_page ):
和
if (is_page('news')
和
if( get_post_type() == 'post' ) {
我使用'template_redirect'而不是'init',以及'if(get_post_type()=='post'){'並且它有效!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.