簡體   English   中英

粘帖WordPress的樣式

[英]styling of sticky posts wordpress

添加的代碼正確地添加了三個最近的便箋,但是我想以不同的方式而不是一行地設置這三個便箋的樣式。 有人可以告訴我如何不同地引用每個粘性帖子。 我知道代碼有點錯誤,因為它為每個粘性帖子分配了一個表格,而我想將每個帖子添加為同一表格的元素

<?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; ?>

如果您只需要知道粘帖的編號(第一個,第二個或第三個),只需添加一個變量,然后在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; ?>

無論如何,您可以在外面使用類包裝器

<div class="specialsticky">

Your wordpress loop here

</div>

和使用

.specialsticky table:nth-child(#) {

分別針對他們

另一種方法是

在循環內的表格標簽中

<table class="specialsticky-<?php echo get_the_ID(); ?>" cellpadding="0" cellspacing="0" border="0" width="95%">

然后您的表格將帶有一個特殊的帖子ID,用於為每個新條目創建新的類樣式

.specialsticky-192 {將目標ID為192

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM