質問編集履歴
1
呼び出したいphpファイルの中身を追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -49,3 +49,99 @@
|
|
49
49
|
[test file='呼び出したいPHPファイル名']
|
50
50
|
|
51
51
|
```
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
【追記:呼び出すPHPファイル】
|
56
|
+
|
57
|
+
```PHP
|
58
|
+
|
59
|
+
<?php
|
60
|
+
|
61
|
+
$categories = get_the_category($post->ID);
|
62
|
+
|
63
|
+
$category_ID = array();
|
64
|
+
|
65
|
+
foreach($categories as $category):
|
66
|
+
|
67
|
+
array_push( $category_ID, $category -> cat_ID);
|
68
|
+
|
69
|
+
endforeach ;
|
70
|
+
|
71
|
+
$args = array(
|
72
|
+
|
73
|
+
'post__not_in' => array($post -> ID),
|
74
|
+
|
75
|
+
'posts_per_page'=> 10,
|
76
|
+
|
77
|
+
'category__in' => $category_ID,
|
78
|
+
|
79
|
+
'orderby' => 'rand',
|
80
|
+
|
81
|
+
);
|
82
|
+
|
83
|
+
$query = new WP_Query($args); ?>
|
84
|
+
|
85
|
+
<?php if( $query -> have_posts() ): ?>
|
86
|
+
|
87
|
+
<?php while ($query -> have_posts()) : $query -> the_post(); ?>
|
88
|
+
|
89
|
+
<div class="related-entry">
|
90
|
+
|
91
|
+
<div class="related-entry-thumb">
|
92
|
+
|
93
|
+
<a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>">
|
94
|
+
|
95
|
+
<?php if ( has_post_thumbnail() ): ?>
|
96
|
+
|
97
|
+
<?php echo get_the_post_thumbnail($post->ID, 'thumb100'); ?>
|
98
|
+
|
99
|
+
<?php else: ?>
|
100
|
+
|
101
|
+
<img src="<?php echo get_template_directory_uri(); ?>/images/no-image.png" alt="NO IMAGE" title="NO IMAGE" width="100px" />
|
102
|
+
|
103
|
+
<?php endif; ?>
|
104
|
+
|
105
|
+
</a>
|
106
|
+
|
107
|
+
</div><!-- /.related-entry-thumb -->
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
<div class="related-entry-content">
|
112
|
+
|
113
|
+
<h4 class="related-entry-title"> <a href="<?php the_permalink(); ?>">
|
114
|
+
|
115
|
+
<?php the_title(); ?>
|
116
|
+
|
117
|
+
</a></h4>
|
118
|
+
|
119
|
+
<p class="related-entry-snippet">
|
120
|
+
|
121
|
+
<?php echo mb_substr( strip_tags( $post->post_content ), 0, 70 ) . ''; ?></p>
|
122
|
+
|
123
|
+
<p class="related-entry-read"><a href="<?php the_permalink(); ?>">記事を読む</a></p>
|
124
|
+
|
125
|
+
</div><!-- /.related-entry-content -->
|
126
|
+
|
127
|
+
</div><!-- /.new-entry -->
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
<?php endwhile;?>
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
<?php else:?>
|
136
|
+
|
137
|
+
<p>記事はありません</p>
|
138
|
+
|
139
|
+
<?php
|
140
|
+
|
141
|
+
endif;
|
142
|
+
|
143
|
+
wp_reset_postdata();
|
144
|
+
|
145
|
+
?>
|
146
|
+
|
147
|
+
```
|