0

如果出现以下情况,我想在我的帖子旁边显示“新”图像:

  1. 它是在 1 到 45 天前发布的。
  2. 45 天后隐藏/禁用“新”图像。

这是我的轮播代码,它显示了最新的 4 个帖子:

`<!------Begin Carousel Cusomizations-------->
<div class="list_carousel">
<a id="prev2" class="prev" href="#">&lt;</a>
<ul id="foo2">
<?php
global $post;
$args = array( 'numberposts' => -1, 'post_type' => 'guides');
    $posts = get_posts($args);
    foreach( $posts as $post ) : setup_postdata($post); ?>
<li class="productCarousel" onclick="document.location.href='<?php echo the_permalink(); ?>';">
<div class="liContent">
<div class="ribbon"><div class="ribbon-new">New</div></div>
<div class="liPadding">
<?php the_post_thumbnail( array(75,75) ); ?>
<h4><?php the_title(); ?></h4>
<p><?php the_excerpt(); ?></p>
<p class="accessGuides"><a href="<?php echo the_permalink(); ?>">Access Guide</a></p>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>
<a id="next2" class="next" href="#">&gt;</a>
<div class="clearfix"></div>
<div id="pager2" class="pager"></div>
</div>    
</div>
<!----End Carousel Customizations----->`

DIV 部分:<div class="ribbon"><div class="ribbon-new">New</div></div>是我的“新”图像横幅的容器。

非常感谢任何帮助!

4

1 回答 1

0
<?php 
// Create a new filtering function that will add our where clause to the query
function filter_where( $where = '' ) {
    // posts in the last 45 days
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-45 days')) . "'";
    return $where;
}
?>
<!------Begin Carousel Cusomizations-------->
<div class="list_carousel">
    <a id="prev2" class="prev" href="#">&lt;</a>
    <ul id="foo2">
    <?php
    global $post;
    $args = array( 'numberposts' => -1, 'post_type' => 'guides');
    add_filter( 'posts_where', 'filter_where' );
    $posts = get_posts($args);
    foreach( $posts as $post ) : setup_postdata($post); ?>
        <li class="productCarousel" onclick="document.location.href='<?php echo the_permalink(); ?>';">
            <div class="liContent">
                <div class="ribbon"><div class="ribbon-new">New</div></div>
                    <div class="liPadding">
                    <?php the_post_thumbnail( array(75,75) ); ?>
                    <h4><?php the_title(); ?></h4>
                    <p><?php the_excerpt(); ?></p>
                    <p class="accessGuides"><a href="<?php echo the_permalink(); ?>">Access Guide</a></p>
                </div>
            </div>
        </li>
    <?php endforeach; 
    remove_filter( 'posts_where', 'filter_where' );
    ?>
    </ul>
    <a id="next2" class="next" href="#">&gt;</a>
    <div class="clearfix"></div>
    <div id="pager2" class="pager"></div>
</div> 
<!----End Carousel Customizations----->`

更新了在过去 45 天内发布帖子时显示文本“新功能区”的答案

<!------Begin Carousel Cusomizations-------->
<div class="list_carousel">
    <a id="prev2" class="prev" href="#">&lt;</a>
    <ul id="foo2">
    <?php
    global $post;
    $args = array( 'numberposts' => -1, 'post_type' => 'guides');
    $posts = get_posts($args);
    foreach( $posts as $post ) : setup_postdata($post); ?>
        <li class="productCarousel" onclick="document.location.href='<?php echo the_permalink(); ?>';">
            <div class="liContent">

                    <?php if( strtotime('-45 days') < strtotime( $post->post_date )  ) {
                        <div class="ribbon">
                            <div class="ribbon-new">New</div>
                        </div>
                    <?php } ?>

                    <div class="liPadding">
                    <?php the_post_thumbnail( array(75,75) ); ?>
                    <h4><?php the_title(); ?></h4>
                    <p><?php the_excerpt(); ?></p>
                    <p class="accessGuides"><a href="<?php echo the_permalink(); ?>">Access Guide</a></p>
                </div>
            </div>
        </li>
    <?php endforeach; ?>
    </ul>
    <a id="next2" class="next" href="#">&gt;</a>
    <div class="clearfix"></div>
    <div id="pager2" class="pager"></div>
</div> 
<!----End Carousel Customizations----->
于 2013-09-26T19:56:19.327 回答