Wordpress PHP中的CSS样式


CSS Styling within some Wordpress PHP?

我有一个想要使用的wordpress代码,但我正在尝试给它一些样式。

<?php global $post;
$current_post = $post; // remember the current post
for($i = 1; $i <= 1; $i++):
  $post = get_previous_post(); // this uses $post->ID
  setup_postdata($post);
  // do your stuff here    
  the_excerpt();
endfor;
$post = $current_post; // restore ?>

也就是说,在它说//在这里做你的事情的地方,我需要将permalink和CSS样式添加到_except中。当前_except在我的博客上调出缩略图。

这是我用来获得2个随机缩略图的代码,希望这能让你知道我想要上面的代码。

<?php
$args = array( 'numberposts' => 2, 'orderby' => 'rand' );
$rand_posts = get_posts( $args );
foreach( $rand_posts as $post ) : ?>
<div class="postgallery" id="post-<?php the_ID(); ?>">
<a class="title" href="<?php the_permalink() ?>" rel="bookmark"><?php the_excerpt(); ?>
<?php
$thetitle = $post->post_title; /* or you can use get_the_title() */
$getlength = strlen($thetitle);
$thelength = 35;
echo substr($thetitle, 0, $thelength);
if ($getlength > $thelength) echo "...";
?>
</a><?php if ($options['tags']) : ?><?php endif; ?> 
</div>
<?php endforeach; ?>

将_except()封装在一组带有id或class的div标记中,这将为您提供通过样式表对摘录内容进行样式化所需的挂钩。