2016-11-24 65 views
0

我是一個初學者在wordpress中,當我正在學習如何製作主題時,我遇到了問題。WordPress的初學者 - style.css不會影響page.php

我使用此代碼在我的functions.php添加CSS:

function learning() { 
    wp_enqueue_style('style', get_stylesheet_uri()); 
} 

它非常適合我的index.php,所以我設計我的默認頁面,我多麼希望。我想改變我在WordPress GUI中創建的頁面的外觀,所以我在我的主題文件夾中創建了page-(otherpage).php文件,並複製了代碼等,並將不同的類分配給page-(otherpage ).PHP。最後,我對我的新類的style.css做了一些修改,但是它沒有改變任何東西。

我該怎麼辦?

+1

你是否正在通過調用其他頁面中的'get_header()'來加載頁眉電子模板?因爲這也會加載您的樣式... –

+0

在此處張貼您的自定義頁面。 –

+0

get_template_part('template-parts/content','page'); <這解決了我的問題。謝謝 –

回答

0

通過function.php附加一個css文件,將下面的代碼添加到functions.php中。

Recommaded不要使用function.php因爲它的主題具體

<?php 
function mypage_head() { 
    echo '<link rel="stylesheet" type="text/css" href="'.get_bloginfo('stylesheet_directory').'/includes/mypage.css">'."\n"; 
} 
add_action('wp_head', 'mypage_head'); 
?> 

方法使用了添加標題爲模板

<?php get_header(); ?> 

創建的模板頁面在這裏:

<?php /* Template Name: CustomPageT1 */ ?> 

<?php get_header(); ?> 

<div id="primary" class="content-area"> 
    <main id="main" class="site-main" role="main"> 
     <?php 
     // Start the loop. 
     while (have_posts()) : the_post(); 

      // Include the page content template. 
      get_template_part('template-parts/content', 'page'); 

      // If comments are open or we have at least one comment, load up the comment template. 
      if (comments_open() || get_comments_number()) { 
       comments_template(); 
      } 

      // End of the loop. 
     endwhile; 
     ?> 

    </main><!-- .site-main --> 

    <?php get_sidebar('content-bottom'); ?> 

</div><!-- .content-area --> 

<?php get_sidebar(); ?> 
<?php get_footer(); ?>