2016-08-19 2 views
0

私はWordPressの開発に新しいが、私はカスタムWordPressのテーマを開発しましたが、私はposts.PostsにCSSを与えることができませんでした。いくつかのCSSは、私がこれを行う方法を私にお勧めします。WordPressテーマの投稿にCSSを与える方法

Posts are appearing on basic way

<?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_footer(); ?> 

私はポストが登場すると、私のワードプレスのテーマのpage.phpのコードされているどのように画像を追加しました。いくつかの助けを求めていること

+0

参照してください。https://codex.wordpress.org/CSS – Dharmendra

答えて

1

は、そのCSSディレクトリ内のファイル名「poststyle.css」を作成してみましょうあなたのテーマディレクトリ内のcssディレクトリを追加して、あなたはheader.phpの中にCSSファイルをリンクすることができ

<link rel="stylesheet" href="<?php echo esc_url(get_template_directory_uri()); ?>/css/poststyle.css" media="screen" title="post-style" charset="utf-8"> 

OR 
    <?php 
    wp_enqueue_style('post-styles' , get_template_directory_uri() . 'css/poststyle.css'); 
    ?> 

が、あなたが与えるか、または「poststyle.css」内のその対応するdivのか、クラスにスタイルを定義することができるように、その前にuがクラスやIDまたはdivの名前を見つける必要があり

今、ちょうどこの例を取る

<?php 
/** 
* The template for displaying pages 
* 
* This is the template that displays all pages by default. 
* Please note that this is the WordPress construct of pages and that 
* other "pages" on your WordPress site will use a different template. 
* 
* @package WordPress 
* @subpackage Twenty_Fifteen 
* @since Twenty Fifteen 1.0 
*/ 

get_header(); ?> 

<div id="primary" class="content-area"> 
    <div id="content" class="site-content" role="main"> 
     <?php while (have_posts()) : the_post(); ?> 
      <div class="title"><?php the_title('<h1>', '</h1>'); ?></div> 
       <div class="pic">  <?php echo get_the_post_thumbnail(get_the_ID() , 'thumbnail' , array('class' => 'img-thumbnail')); ?></div> 
       <div class="content"> <?php the_content() ; ?></div> 
     <?php endwhile; // end of the loop. ?> 
    </div><!-- #content --> 
</div><!-- #primary --> 

<?php get_footer(); ?> 

は今、あなたは、クラスにスタイルを与えることができます=「サイトコンテンツ」またはクラス=「コンテンツ・エリア」、クラス=「タイトル」、あなたのポストショーのテンプレートのクラス=「コンテンツ」


しかし、包みなさい何テンプレートパーツ内にある別のテンプレートをインポートしていることです。content.phpファイルすべての投稿内容コードがそこにある

+0

はあなたのことができてくださいどのように私のpage.phpのクラス/ IDを追加することができますか?私に例を教えていただけますか? –

+0

これはcssとjsを直接追加するのは悪い考えです。 – anik4e

1

テーマとプラグインを作成するには、Wordpressコーディング標準に従わなければなりません。 cssとjsを追加するには、テーマ「js」と「css」の中に2つのフォルダを作成します。その後

if(!function_exists('theme_style')): 
    function theme_style(){ 
     wp_enqueue_script('main-js', get_template_directory_uri().'/js/main.js',array(),false,true); 
     wp_enqueue_style('main-css', get_template_directory_uri(). '/css/main.css', array(),false,'all');  
    } 
    add_action('wp_enqueue_scripts','theme_style'); 
endif; 

あなたはファイル名のmain.jsとのmain.cssを変更することができますのfunctions.php内でこのコードを追加

関連する問題