[英]styling of sticky posts wordpress
The added code correctly adds the three recent sticky notes, but I want to style the three sticky notes differently, not in a line. 添加的代码正确地添加了三个最近的便笺,但是我想以不同的方式而不是一行地设置这三个便笺的样式。 Can someone tell me how I can reference each sticky post differently.
有人可以告诉我如何不同地引用每个粘性帖子。 I know the code is a little wrong as it assigns a table to each sticky post whereas I want to add each post as elements of the same table
我知道代码有点错误,因为它为每个粘性帖子分配了一个表格,而我想将每个帖子添加为同一表格的元素
<?php get_header(); ?>
<?php if(is_home() && !is_paged()) { ?>
<?php query_posts(array('post__in'=>get_option('sticky_posts')));
$sticky = get_option( 'sticky_posts' );
rsort($sticky);
$sticky = array_slice( $sticky, 0, 3);
query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) ); ?>
<?php while (have_posts()) : the_post(); ?>
<table cellpadding="0" cellspacing="0" border="0" width="95%">
<tr>
<td valign="top">
<div class="masthead-1" style="float: left;">
<?php if ( has_post_thumbnail() && ! post_password_required() && !is_attachment() ) : ?>
<a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_post_thumbnail(); ?>
<?php endif; ?>
<div class="mast11" style="opacity: 0.5;"></div>
<div class="mast12">
<h1 class="lbl2"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><div style="clear:both"></div></h1>
</div>
</div></td></table>
<?php endwhile; ?>
If all you need to know is the number of the sticky post (1st, 2nd or 3rd), just add a variable which you increment at the end of the while
loop. 如果您只需要知道粘帖的编号(第一个,第二个或第三个),只需添加一个变量,然后在
while
循环结束时增加即可。
<?php $i = 0; while (have_posts()): the_post(); ?>
<!-- do whatever you want to do here, using $i as a reference to which post you're currently working with -->
<?php $i++; endwhile; ?>
anyway You can use a class wrapper on the outside 无论如何,您可以在外面使用类包装器
<div class="specialsticky">
Your wordpress loop here
</div>
and use 和使用
.specialsticky table:nth-child(#) {
to target them each differently 分别针对他们
The other way to do this is 另一种方法是
in your table tag inside your loop 在循环内的表格标签中
<table class="specialsticky-<?php echo get_the_ID(); ?>" cellpadding="0" cellspacing="0" border="0" width="95%">
and then your tables will have a spcial post id attached to creating a new class style for each new entry 然后您的表格将带有一个特殊的帖子ID,用于为每个新条目创建新的类样式
.specialsticky-192 {
will target a post id of 192 .specialsticky-192 {
将目标ID为192
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.