phpのパーマリンクがうまくいかない
-
Q.数週間、様々なサイトを見ながら、試行錯誤しましたが、
ブログのbuttonや記事をクリックした時に、page-blogへ変移したいのですが、
うまくできません。原因と解決策のご教授頂けると嬉しいです。<section class="blog <?php echo $slug; ?>"> <div class="inner wow animate__animated animate__fadeIn" data-wow-offset="100"> <h2 class="jp-ttl">ブログ</h2><!-- /.jp-ttl --> <h4 class="en-ttl">Blog</h4><!-- /.en-ttl --> <dl class="blog-list"> <dl class="blog-list"> <?php $query_args = array( 'post_status'=> 'publish', 'post_type'=> 'post', 'order'=>'DESC', 'category_name' => '', 'posts_per_page'=>5 ); $the_query = new WP_Query( $query_args ); if ( $the_query->have_posts() ) : //記事が存在した場合 while ( $the_query->have_posts() ) : $the_query->the_post();//ループのインクリメントの役割、これがないと無限ループになるので注意 $link = get_permalink($post->ID);//記事url $category = get_the_category( $post->ID ); // foreach($cats as $cat): // if($category->parent) echo $catgory->cat_name; // endforeach; $title = get_the_title($post->ID);//記事タイトル ?> <div class="row"> <dt><?php echo $category ; ?></dt> <dd><a>"><?php echo $title;?></a></dd> </div> <?php endwhile; else: //記事が存在しなかった場合 echo '<div class="row">'; echo '<dd><a href="/">すみません。ただいま記事を準備中です。<br>少々お待ちください。</a></dd>'; echo '</div>'; endif; wp_reset_query();//クエリをリセット ?> </dl><!-- /.blog-list --> <div class="blog-link cmn-btn"><a> ">もっと見る</a></div> </div><!-- /.inner --> </section><!-- /.blog -->固定page↓
<?php get_header();?> <?php $paged = $_GET['pagenum']; global $NO_IMAGE_URL; ?> <main class="article"> <div class="cmn-mv"></div> <div class="breadcrumb"> <?php breadcrumb( $post->ID );//パンくずを表示(functions.php) ?> </div> <div class="article-section cmn-section"> <div class="inner"> <h2 class="cmn-title"> <p class="main">ブログ</p> <span class="sub">blog</span> </h2> <div class="article-cont"> <ul class="article-list"> <?php $query_args = array( 'post_status'=> 'publish', 'post_type'=> 'post', 'order'=>'DESC', 'post_per_pages' => 10, 'paged'=>$paged ); $the_query = new WP_Query( $query_args ); if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); $thumbnail = (get_the_post_thumbnail_url( $post->ID, 'medium' )) ? get_the_post_thumbnail_url( $post->ID, 'medium' ) : get_template_directory_uri().$NO_IMAGE_URL; $title = max_excerpt_length(get_the_title( $post->ID ), 60);//記事タイトルを取得し、文字数を制限(functions.php) $desc = get_the_excerpt( $post->ID );//抜粋を取得 $data = get_the_modified_date( 'Y-m-d', $post->ID );//更新日を取得 $category = get_the_category( $post->ID )[0]->name;//カテゴリを取得(並び順で1番目にあるものを1つ) $link = get_permalink( $post->ID ); ?> <?php $query_args = array ( 'post_status'=> 'publish', 'post_type' => 'post', 'order' => 'DESC', 'post_per_pages' => 10, 'paged' =>$paged ); <li class="blog-item"> <div class="blog-img"> <?php if( $category ){ echo '<p class="category">'.$category.'</p>'; }; ?> <img />" alt="旅館雰囲気"> </div><!-- /.blog-img --> <div class="blog-txt"> <time class="time" datetime="<?php echo $data;?>"><?php echo $data;?>>2020-0</time><!-- /.time --> <h5><?php echo $title;?></h5> <p class="blog-txt_desc">?php echo $desc;?></p><!-- /.blog-txt_desc --> </div><!-- /.blog-txt --> <a>"></a> </li><!-- /.blog-item --> <?php if( $category ){ echo '<p class="category">'.$category.'</p>'; }; ?> <p class="image"><img />" alt=""></p> </div> </a> </li> <?php endwhile; endif; wp_reset_query();//クエリをリセット ?> </ul> </div> <div class="article-pager"> <?php $page_url = $_SERVER['REQUEST_URI'];//ページurlを取得 $page_url = strtok( $page_url, '?' );//パラメータは切り捨て $the_category_id = null; pagination($the_query->max_num_pages, $the_category_id, $paged, $page_url);//ページネーションを表示(functions.php) ?> </div> </div> </div> </main> <?php get_footer();?>`
ヘルプの必要なページ: [リンクを見るにはログイン]
3件の返信を表示中 - 1 - 3件目 (全3件中)
3件の返信を表示中 - 1 - 3件目 (全3件中)
トピック「phpのパーマリンクがうまくいかない」には新たに返信することはできません。