我是WordPress开发的新手,我已经开发了一个自定义的WordPress主题,但是我无法将CSS提交给posts.Posts以非常普通的方式呈现,但是我想给一些CSSs,请提出我如何做到这一点。
<?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(); ?>
我添加了图像,这些内容是如何显示的以及wordpress主题的page.php代码。寻求帮助
最佳答案
在主题目录中添加一个css目录,然后在该css目录中创建一个文件名“ poststyle.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' );
?>
但在此之前,您需要找出类或id或div名称,以便您可以在“ poststyle.css”中为相应的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(); ?>
现在,您可以为class =“ site-content”或class =“ content-area”,class =“ title”,class =“ content”指定样式
但是,如果您使用发布秀模板,那么您正在做的是导入另一个模板,该模板位于template-parts目录content.php文件中,其中所有显示代码的发布内容都在其中