WordPress如何定义指定文章的样式

通过post_class() 函数及post ID属性来定义指定文章或某些类别的文章的样式。

 通过修改<div <?php post_class() ?> id=“post-<?php the_ID(); ?>”> ,来实现定义指定文章或某些类别文章的样式。

打开single.php,将其中有关文章内容部分的代码修改成如下形式:

<?php if (have_posts()) : ?>
  <?php while (have_posts()) : the_post(); ?>
  <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
  <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
  <?php the_content(); ?>
  </div>
  <?php endwhile; else: ?>
  <?php _e('Sorry, no posts matched your criteria.'); ?>
  <?php endif; ?> 

 

主要是第三行代码部分,添加<?php post_class() ?> 及<?php the_ID(); ?> 
通过上述代码后,我们察看具体文章的源代码就会发现如下样式的代码:

<div class=”post sticky hentry category-design tag-news tag-wordpress tag-markup”  id=”post-23″>。

如果需要定义指定类别的的文章样式,只需定义下列类:

 .post
 .hentry
 .sticky
 .category-misc
 .tag-news
 .tag-wordpress
 .tag-markup

如果需定义指定某篇文章的样式,只需定义post-ID即可。

例如:

#post-23{
 background:#aaa;
	}  

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

:wink: :-| :-x :twisted: :) 8-O :( :roll: :-P :oops: :-o :mrgreen: :lol: :idea: :-D :evil: :cry: 8) :arrow: :-? :?: :!:

无觅相关文章插件,快速提升流量

任鸟飞网页设计博客 谜题推理 No.1 Web Design Gallery IndustryIdea LookForDesign AWebGallery Mobile Web Template iDesign Wallpaper Big Funny Picture iPhone Faves iPhone Mobi iPad Faves Android Faves BlackBerry Faves Best Design Magazine All Banner Templates Blog Earn Tips 是谁啊 只爱美人 家乡美 唯美爱 美人衣妆 AutoCAD 2D | Pro/E 3D江苏名企The HTML5 Templates