こちらのコードをfunctionに記述したらエラーになりました
どこか間違ってるのでしょうか?
// カテゴリ別新着 function event_list_alls( $cat_id ) { $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; global $post; $args = array( 'posts_per_page' => 10, 'cat' => $cat_id, 'paged' => $paged, 'orderby' => 'date', 'order' => 'DESC', 'post_status' => 'publish', ); $myposts = get_posts( $args ); foreach( $myposts as $post ) { setup_postdata($post); $image = get_field('img1'); $url = $image['url']; //画像のURL $alt = $image['alt']; //画像のalt $title = $image['title']; //画像のタイトル $size = 'thumbnail'; //出力サイズを変数に格納 $imgThumb = $image['sizes'][ $size ]; //サムネイル画像のURL $width = $image['sizes'][ $size . '-width' ]; //サムネイル画像の幅サイズ $t_start = date_create(get_field('start')); $t_end = date_create(get_field('end')); $week = array("日", "月", "火", "水", "木", "金", "土"); $w = (int)date_format($t_start, 'w'); $youbi1 = $week[$w]; $w = (int)date_format($t_end, 'w'); $youbi2 = $week[$w]; $cats = get_the_category();//選択したカテゴリ //var_dump($cats) ?> <li class="post"> <div class="flex"> <div class="l"> <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> <img src="<?php echo $imgThumb; ?>" width="<?php echo $width; ?>" alt="<?php echo $alt; ?>" /> </a> </div> <div class="r"> <div class="flex between bar"> <div class="cat <?php if($cats[0]->cat_ID == 4): ?> bgcolor1 <?php elseif($cats[0]->cat_ID == 2): ?> bgcolor2 <?php elseif($cats[0]->cat_ID == 5): ?> bgcolor3 <?php endif; ?> "><?php echo $cats[0]->cat_name; ?></div> <div class="date">開催日:<?php echo date_format($t_start,'m月d日'); ?>(<?php echo $youbi1 ?>)〜<?php echo date_format($t_end,'m月d日'); ?>(<?php echo $youbi2 ?>)</div> </div> <p class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p> </div> </li> <?php } wp_reset_postdata(); } add_action( 'event_list_all', 'event_list_alls' ); ?>
どのようなエラーでしょうか。ほかにもどのような経緯で書いたのか、どうしたいのかなどの目的 などが抜けており、内容が不足しているため回答は見込めないと思います。エラーを直すだけで目的が達せられるとも限りません。
回答2件
あなたの回答
tips
プレビュー