大変申し訳ありませんでした。実は当方がやりたいことがございまして、ワードプレスの最近の投稿のウィジェットのところで、そこの記事を選択すると、single.phpが表示されてしまいます。そうではなく、投稿一覧の方に行ってほしくて、何ページ目かをゲットしたかったです。ゲットできても上手くいくかわからないので、無責任な質問でした。申し訳ございません。やりたいことは、最近の投稿のところを選択して、リンクが投稿一覧のほうに遷移することです。
index.php
php
1<?php get_header(); ?> 2 <div id="main" class="container"> 3 <div id="posts"> 4 5 <?php if(have_posts()): 6 while(have_posts()): 7 the_post(); 8 9 ?> 10 <?php $p_slug = get_page_uri(get_the_ID()); ?> 11 <div id="<?php echo $p_slug ?>"></div> 12 13 <div id="test"></div> 14 <div class="post"> 15 <div class="post-header"> 16 <h2> 17 <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> 18 </h2> 19 </div> 20 <div class="post-meta"> 21 <?php echo get_the_date(); ?> 【<?php the_category(', ') ?>】 22 </div> 23 <div class="post-content"> 24 <div class="post-image"> 25 26 <?php if(has_post_thumbnail()): ?> 27 <?php the_post_thumbnail(array(100, 100)); ?> 28 <?php else: ?> 29 <img src="<?php echo get_template_directory_uri(); ?>/images.jpg" width="100" height="100"> 30 <?php endif; ?> 31 32 </div> 33 <div class="post-body"> 34 <div class="post-body-excerpt"> 35 <?php the_content('',false,''); ?> 36 </div> 37 38 <div class="more"><a href="<?php the_permalink(); ?>">続きを読む</a></div> 39 <a href="<?php echo '#'.$p_slug ?>">ここ</a> 40 </div> 41 42 </div> 43 </div> 44 <?php endwhile; 45 else: 46 ?> 47 48 <p>記事はありません!</p> 49 50 <?php endif; 51 ?> 52 53 <div class="navigation"> 54 <div class="prev"><?php previous_posts_link(); ?></div> 55 <div class="next"><?php next_posts_link(); ?></div> 56 </div> 57 </div><!--/posts--> 58 <?php get_sidebar(); ?> 59 </div><!--/main --> 60 <?php get_footer(); ?>
single.php
php
1<?php get_header(); ?> 2 <div id="main" class="container"> 3 <div id="posts"> 4 5 <?php if(have_posts()): 6 while(have_posts()): 7 the_post(); 8 9 ?> 10 <div class="post"> 11 <div class="post-header"> 12 <h2> 13 <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> 14 </h2> 15 </div> 16 <div class="post-meta"> 17 <?php echo get_the_date(); ?> 【<?php the_category(', ') ?>】 18 </div> 19 <div class="post-content"> 20 <p> 21 <?php the_content(); ?> 22 </p> 23 24 </div> 25 </div> 26 27 <div class="navigation"> 28 <div class="prev"><?php previous_post_link(); ?></div> 29 <div class="next"><?php next_post_link(); ?></div> 30 </div> 31 32 <?php endwhile; 33 else: 34 ?> 35 36 <p>記事はありません!</p> 37 38 <?php endif; 39 ?> 40 41 </div><!--/posts--> 42 <?php get_sidebar(); ?> 43 </div><!--/main --> 44 <?php get_footer(); ?>
sidebar.php
php
1<div id="sidebar"> 2 <?php dynamic_sidebar(); ?> 3 </div><!--/sidebar-->
header.php
php
1<!DOCTYPE html> 2<html lang="ja"> 3 <head> 4 <meta charset="UTF-8"> 5 <title><?php wp_title('|', true, 'right'); bloginfo('name'); ?></title> 6 <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.18.1/build/cssreset/cssreset-min.css"> 7 <link rel="stylesheet" type="text/css" href="<?php echo get_stylesheet_uri(); ?>"> 8 <?php wp_head(); ?> 9 </head> 10 <body> 11 <?php if(is_front_page()) { if (get_header_image() !='') { ?> 12 <div id="main_image"> 13 <img src="<?php header_image(); ?>" alt="" title="" /> 14 </div> 15 <?php }; }; ?> 16 <div id="header" class="container"> 17 <h1><a href="<?php echo home_url('/'); ?>"><?php bloginfo('name');?></a></h1> 18 <div class="wrapper"><?php wp_nav_menu(); ?></div> 19 </div><!--/header--> 20
page.php
php
1<?php get_header(); ?> 2 <div id="main" class="container"> 3 <div id="posts"> 4 5 <?php if(have_posts()): 6 while(have_posts()): 7 the_post(); 8 9 ?> 10 <div class="post"> 11 <div class="post-header"> 12 <h2> 13 <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> 14 </h2> 15 </div> 16 17 <div class="post-content"> 18 <?php the_content(); ?> 19 20 </div> 21 </div> 22 23 <?php endwhile; 24 else: 25 ?> 26 27 <p>ページはありません!</p> 28 29 <?php endif; 30 ?> 31 32 </div><!--/posts--> 33 <?php get_sidebar(); ?> 34 </div><!--/main --> 35 <?php get_footer(); ?>
footer.php
php
1<div id="footer" class="container"> 2 Copyright 2017<?php if(date("Y")!=2017) echo date("-Y"); ?> All right reserved, gomatan1258 3 </div><!--/footer--> 4 <?php wp_footer(); ?> 5 6 </body> 7</html>
functions.php
php
1<?php 2 3add_theme_support( 'custom-header' ); 4 5add_theme_support('menus'); 6 7register_sidebar( 8 array( 9 before_widget => '<div class="widget">', 10 after_widget => '</div>', 11 before_title => '<h3>', 12 after_title => '</h3>', 13 ) 14); 15 16add_theme_support('post-thumbnails'); 17 18$cssdir = get_stylesheet_directory_uri(); 19wp_enqueue_script( 'theme-script', $cssdir.'/script.php', array('jquery')); 20 21?>
当方はワードプレス初心者ですがよろしくお願いします。
追記です。
javascriptが使えるプラグイン
javascript
1jQuery(function() { 2 jQuery(".menu li").hover(function() { 3 jQuery(this).children('ul').show(); 4 }, function() { 5 jQuery(this).children('ul').hide(); 6 });//プルダウンメニューが表示されます 7 8 var page; 9 10 jQuery('.more a').on('click', function(event) { 11 //aリンクの動作を停止 12 event.preventDefault(); 13 //リンク先URLを取得 14 page = jQuery(this).attr('href'); 15 jQuery(this).parent().load(page+' div.post-content p',function(){ 16 jQuery(this).parent().children().eq(0).hide(); 17 }); 18 //続きを読む ajaxでページ遷移せずにsingle.phpの一部が表示される 19 }); 20 jQuery('a[href^=#]').click(function(){ 21 var speed = 500; 22 var href= jQuery(this).attr("href"); 23 var target = jQuery(href == "#" || href == "" ? 'html' : href); 24 var position = target.offset().top; 25 jQuery("html, body").animate({scrollTop:position}, speed, "swing"); 26 return false; 27 });//ページ内リンクすることができる 28}); 29
javascriptのほうが間違っていたので変更しました。
最新記事ではなく最近の投稿と書き直しました。
回答1件
あなたの回答
tips
プレビュー