0

以前にこれをやろうとして失敗したことがあります。おそらく、それがどのように機能するのか理解していないだけかもしれません。誰かが以前にこれを行ったことがあり、私を助けることができます。

wordpress を使用して学校のウェブサイトを構築すると、科目ごとのクラスがあり、次のように曜日ごとにリストされます。

月曜日

  • 数学
  • 英語
  • 化学

火曜日

  • 化学

水曜日

  • 数学
  • 歴史

これを構築するとき、「クラス」と呼ばれるカスタム投稿タイプを使用しています。次に、カスタム投稿フィールドを使用して、クラスがいつであるかを含むすべてのデータを time() 形式で入力しています (日付ピッカーを使用) )

これは私が日付/時刻をエコーする方法です: <?php echo(types_render_field("date-and-time", array("format"=>"l","arg2"=>"val2"))); ?>

さて、現在、これは私のループです:

ループの要旨

しかし、まったく機能せず、曜日をリストしていますが、その日を数回リストするので、水曜日に4つの投稿がある場合は、水曜日、水曜日、水曜日、水曜日をリストします。

投稿をループして日付をエコーするだけなので、これは理にかなっています。

基本的に、私は書き込もうとしています:

- loop days of the week 7 days ahead 
    - loop posts under the date heading based on custom field date

私はもともとこれにスケジュールされた投稿を使用するつもりでしたが、ワードプレスで投稿をスケジュールすることは、コンピューターに精通していない人にとっては簡単ではありません.カスタムフィールドを使用すると、スタイルを設定してTYPESが提供するDATE PICKERを使用できます.

誰かが私を助けることができれば、それは素晴らしいことです!

4

1 に答える 1

0

私の友人は私の問題の素晴らしい解決策を作成することができました.コードをここに投稿します.将来的に誰かを助けることを願っています.

<?php 
 $begin = strtotime('Monday last week'); // Year . Week
 $end = $begin + (21 * 24 * 60 * 60);
 $week = -1;
 $day = -1;
 $table = FALSE;
 $this_week = date('W');

query_posts( 
array( 
    'post_type' => 'classes',               // Custom Post Type
    'order' => 'asc',                       // Order with earliest first
    'orderby' => 'wpcf-date-and-time',      // Order by the custom field
    'posts_per_page' => -1,                 // Show all
    'meta_key' => 'wpcf-date-and-time',     // Key is the custom field
    'meta_value' => array($begin, $end),    // Array of the current month and next
    'meta_compare' => 'BETWEEN',            // Between Being and End
    'author' => $author_id                  // Show only the author
    ) 
);                                          // Get posts between now and then

if (have_posts()) : while (have_posts()) : the_post(); 
    $do_not_duplicate = $post->ID;
    $time = types_render_field("date-and-time", array("arg1"=>"val1","raw"=>"true")); // Your custom field
    $current_week = date('W', $time);
    $current_day = date('l', $time);
    if ($current_week > $week) {
        if ($table) {
            echo "</table>";
            $table = FALSE;
        }
        $week = $current_week;
        if ($week > $this_week)          { $week_str = 'Next week';}
        else if ($week < $this_week) { $week_str = 'Last week';}
        else                                                 { $week_str = 'This week';}
        echo '<h2 class="">' . $week_str . '</h2>';
    }
    if ($current_day != $day) {
        $day = $current_day;
        if ($table) {
            echo "</table>";
            $table = FALSE;
        }
        $table = TRUE;
        echo '<h3 class="">' . $day . '</h3>';
        echo '<table>
                <thead>
                    <tr>
                        <td>Location</td>
                        <td>Venue</td>
                        <td>Time</td>
                        <td>age</td>
                    </tr>
                </thead>';
    }
    ?>

<tr>
    <td><?php the_title(); ?></td>
    <td><?php echo(types_render_field("location", array("arg1"=>"val1","arg2"=>"val2"))); ?></td>
    <td><?php echo(types_render_field("venue", array("arg1"=>"val1","arg2"=>"val2"))); ?></td>
    <td><?php echo get_the_term_list( $post->ID, 'age-group', '', ', ', '' ) ?></td>
</tr>   

<?php endwhile; else: ?>
<p>We don't currently have any classes available on this day,
but we can <strong>book your child in for a class</strong>, please get in touch to organise this</p>
 <?php endif; wp_reset_query() ?>                                               
于 2013-08-05T13:52:49.560 に答える