1

我目前正在为一个广播网站编写一个广播部分,并试图在广播中显示当前节目的标题和元数据。

为此,我创建了自定义字段Start TimeEnd Time设置了一个 query_posts 命令,以根据当前时间大于Start Time和小于的值来检索显示帖子End Time

date_default_timezone_set('Europe/London');
$time = date("G:i");
$showstart = get_post_meta($post->ID, 'Start Time', true);
$showend = get_post_meta($post->ID, 'End Time', true);
if($time<$showstart)
        {$startnext = $showstart;}
if($showstart<=$time && $time<$showend)
        {$starttime = $showstart;}
if( date( 'w' ) == 0 ) {
       query_posts('cat=17&posts_per_page=1&offset=0&orderby=meta_value_num&   meta_value_num=$starttime&meta_key=Start Time&order=ASC');
    }
    else if( date( 'w' ) == 1 ) {
    query_posts('cat=18&posts_per_page=1&offset=0&orderby=meta_value_num&meta_value_num=$starttime&meta_key=Start Time&order=ASC');
    }
    else if( date( 'w' ) == 2 ) {
    query_posts('cat=12&posts_per_page=1&offset=0&orderby=meta_value_num&meta_value_num=$starttime&meta_key=Start Time&order=ASC');
    }
    else if( date( 'w' ) == 3 ) {
    query_posts('cat=13&posts_per_page=1&offset=0&orderby=meta_value_num&meta_value_num=$starttime&meta_key=Start Time&order=ASC');
    }
    else if( date( 'w' ) == 4 ) {
    query_posts('cat=14&posts_per_page=1&offset=0&orderby=meta_value_num&meta_value_num=$starttime&meta_key=Start Time&order=ASC');
    }
    else if( date( 'w' ) == 5 ) {
    query_posts('cat=15&posts_per_page=1&offset=0&orderby=meta_value_num&meta_value_num=$starttime&meta_key=Start Time&order=ASC');
    }
    else if( date( 'w' ) == 6 ) {
    query_posts('cat=16&posts_per_page=1&offset=0&orderby=met   a_value_num&meta_value_num=$starttime&meta_key=Start Time&order=ASC');
    }

帖子循环如下所示:

// The Loop
while ( have_posts() ) : the_post();?>
<div id="listenlivebanner">

<div id="showwrap">
<div id="showdetails">
<div id="nowplayingimg">
    <div>
    <div style="height: 150px; display:block; margin-left: auto; margin-right: auto;"><?php the_post_thumbnail('onair-thumb', array('title' => ''.get_the_title().'' )); ?></div>
    </div>
</div>
    <div class="listenlive">
        <h3>LIVE:</h3><p class="showname"><?php $short_title = substr(the_title('','',FALSE),0,18);
                                            echo $short_title; 
                                            if (strlen($short_title) > 17){ 
                                                echo '...'; 
                                            }  ?></p>

但是,目前它只是按照我设置的顺序检索第一个节目帖子,而不是根据当前时间进行更改。如何让它发挥作用?

编辑:

从 query_posts 更改为新的 WP_Query 但仍然没有运气 - 现在它只显示页面的标题而不是我要检索的帖子的标题......

下面是代码:

 else if( date( 'w' ) == 3 ) {
    new WP_Query( array( 'cat' => 13, 'posts_per_page' => 1, 'offset' => 0, 'orderby' => 'meta_value_num', 'order' => 'DESC', 'meta_query' => array( 
                                                array('key' => 'Start_Time', 'value' => '$time', 'compare' => '<=', 'type' => 'TIME' )
                                              )
                        )
                );
    }
    else if( date( 'w' ) == 4 ) {
    new WP_Query( array( 'cat' => 14, 'posts_per_page' => 1, 'offset' => 0, 'orderby' => 'meta_value_num', 'order' => 'DESC', 'meta_query' => array( 
                                                array('key' => 'Start_Time', 'value' => '$time', 'compare' => '<=', 'type' => 'TIME' )
                                              )
                        )
                );
    }
4

1 回答 1

0

我会在你的设置中改变什么:

于 2013-09-01T23:54:34.370 回答