WordPress 改変ウィジェット一覧
この記事について
本サイトで使用している改変ウィジェットのうち、個別記事にするほどでもないものをまとめたページです。
大半がテーマ「luxeritas」のコードが元となっています。
元コードのライセンス「GPL v2 or later」に準じたソースコードの公開を目的としています。
順次更新予定です。
各ファイルのショートコードでの呼び出しは以下のページを参照してください。
関連記事
目的:ウィジェット化して自由な場所に置きたい
・luxech > myphpfiles > mobile_related.php
<?php
/**
* Luxeritas WordPress Theme - free/libre wordpress platform
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* @copyright Copyright (C) 2015 Thought is free.
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
* @author LunaNuko
* @link https://thk.kanzae.net/
* @translators rakeem( http://rakeem.jp/ )
*/
?>
<div id="related">
<?php
global $luxe, $post, $wpdb;
$categories = get_the_category( $post->ID );
$tags = get_the_tags( $post->ID );
$cat_post_id = array();
$tag_post_id = array();
// 関数使うより直接 SELECT 文発行した方が速い
// 同じカテゴリに属する post_id 取得
if( !empty( $categories ) ) {
foreach( (array)$categories as $val ) {
//$cat_post_id = wp_parse_args( $cat_post_id, $wpdb->get_col( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = $val->cat_ID AND object_id != $post->ID" ) );
$cat_post_id = wp_parse_args( $cat_post_id, $wpdb->get_col( "SELECT object_id FROM $wpdb->term_relationships, $wpdb->term_taxonomy WHERE $wpdb->term_taxonomy.term_id = $val->cat_ID AND $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id AND object_id != $post->ID" ) );
}
shuffle( $cat_post_id );
}
// 同じタグに属する post_id 取得
if( !empty( $tags ) ) {
foreach( (array)$tags as $val ) {
//$tag_post_id = wp_parse_args( $tag_post_id, $wpdb->get_col( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = $val->term_taxonomy_id AND object_id != $post->ID" ) );
$tag_post_id = wp_parse_args( $tag_post_id, $wpdb->get_col( "SELECT object_id FROM $wpdb->term_relationships, $wpdb->term_taxonomy WHERE $wpdb->term_taxonomy.term_taxonomy_id = $val->term_taxonomy_id AND $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id AND object_id != $post->ID" ) );
}
shuffle( $tag_post_id );
}
// 同じタグに属する記事を優先表示させるため wp_parse_args 使わない( wp_parse_args だと同じ値があった時に、配列の後ろが残る形になるため )
//$ = wp_parse_args( $tag_post_id, $cat_post_id );
// key は使わず単なる連番なので、array_merge で結合するより + 演算子で結合しちゃった方が速い
//$post_in = array_unique( $tag_post_id + $cat_post_id );
// と思ったけど、array_merge じゃないと要素が消えるパターンがあるから、やっぱり array_merge にしたw
$post_in = array_unique( array_merge( $cat_post_id, $tag_post_id ) );
//$sticky_posts = get_option( 'sticky_posts' );
$args = array(
'posts_per_page'=> 5,
'post__in' => $post_in,
'orderby' => 'post__in',
);
$st_query = new WP_Query($args);
if( $st_query->have_posts() === true ) {
while( $st_query->have_posts() === true ) {
$wp_upload_dir = wp_upload_dir();
$st_query->the_post();
?>
<div class="toc clearfix mobile-related">
<?php
if( isset( $luxe['thumbnail_visible'] ) ) {
$attachment_id = false;
$echo = false;
$post_thumbnail = has_post_thumbnail();
if( $post_thumbnail === false && isset( $luxe['no_img'] ) ) {
$attachment_id = thk_get_image_id_from_url( $luxe['no_img'] );
if( $attachment_id !== false ) {
$post_thumbnail = true;
$echo = true;
$aria_label = 'aria-label="No Imaage"';
}
}
if( $post_thumbnail === true ) { // サムネイル
$thumb = 'thumb100';
$image_id = $attachment_id;
if( $attachment_id === false ) {
$image_id = get_post_thumbnail_id();
}
$image_url = wp_get_attachment_image_src( $image_id, $thumb );
if( isset( $image_url[0] ) && stripos( $image_url[0], '-100x100.' ) !== false ) {
$image_path = str_replace( $wp_upload_dir['baseurl'], $wp_upload_dir['basedir'], $image_url[0] );
if( file_exists( $image_path ) === false ) {
$thumb = 'thumbnail';
}
}
else {
$thumb = 'thumbnail';
}
if( $attachment_id === false ) {
$attachment_id = get_post_thumbnail_id();
$attachment_image = wp_get_attachment_image( $attachment_id );
if( isset( $luxe['amp'] ) ) {
$aria_label = 'aria-hidden="true"';
}
else {
if( !empty( $attachment_image ) && stripos( $attachment_image, 'alt="' ) !== false ) {
$aria_label = substr( $attachment_image, stripos( $attachment_image, 'alt="' ) + 5 );
$aria_label = substr( $aria_label, 0, stripos( $aria_label, '"' ) );
if( empty( $aria_label ) ) {
$aria_label = 'aria-label="' . thk_random_alt_or_aria_label( 'Thumbnail of related posts' ) . '"';
}
else {
$aria_label = 'aria-label="' . $aria_label . '"';
}
}
else {
$aria_label = 'aria-label="' . thk_random_alt_or_aria_label( 'Thumbnail of related posts' ) . '"';
}
}
}
else {
if( isset( $luxe['amp'] ) ) {
$aria_label = 'aria-hidden="true"';
}
else {
$aria_label = 'aria-label="No Image"';
}
}
?><figure class="term"><a href="<?php the_permalink() ?>" <?php echo $aria_label; ?>><?php
if( $echo === true ) {
$attachment_image = wp_get_attachment_image( $attachment_id, $thumb );
echo thk_alt_attribute( $attachment_image, 'Thumbnail of related posts' );
}
else {
//the_post_thumbnail( $thumb );
$get_post_thumbnail = get_the_post_thumbnail( null, $thumb );
echo thk_alt_attribute( $get_post_thumbnail, 'Thumbnail of related posts' );
}
?></a></figure><?php
}
else {
$aria_label = isset( $luxe['amp'] ) ? 'aria-hidden="true"' : 'aria-label="No Image"';
?><figure class="term"><a href="<?php the_permalink() ?>" <?php echo $aria_label; ?>><img src="<?php echo TURI; ?>/images/no-img-100x100.png" alt="No Image" title="No Image" width="100" height="100" /></a></figure>
<?php
}
}
?>
<div class="excerpt">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
</div>
</div>
<?php
}
}
else {
?>
<p class="no-related"><?php echo __( 'No related posts yet.', 'luxeritas' ); ?></p>
<?php
}
wp_reset_postdata();
?>
</div>
CSS
.mobile-related{
padding: 0 !important;
margin: 0 !important;
border-top: none !important;
display: flex;
align-items: center;
}
.mobile-related .term{
margin: 0;
}
.mobile-related .term img{
padding: 0;
margin: 0 5px 2px 0 !important;
border: 1px solid #eee;
border-radius: initial !important;
box-shadow: none;
max-width: 50px;
max-height: 50px;
box-sizing: border-box;
}
.mobile-related .excerpt h3{
margin: 0 !important;
font-size: 1rem !important;
}
.mobile-related .excerpt h3 a{
color: #111;
font-size: 1.3rem !important;
line-height: 1.5rem !important;
font-weight: 700;
}
・luxech > myphpfiles > desktop_related.php
<?php
/**
* Luxeritas WordPress Theme - free/libre wordpress platform
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* @copyright Copyright (C) 2015 Thought is free.
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
* @author LunaNuko
* @link https://thk.kanzae.net/
* @translators rakeem( http://rakeem.jp/ )
*/
?>
<div id="related">
<?php
global $luxe, $post, $wpdb;
$categories = get_the_category( $post->ID );
$tags = get_the_tags( $post->ID );
$cat_post_id = array();
$tag_post_id = array();
// 関数使うより直接 SELECT 文発行した方が速い
// 同じカテゴリに属する post_id 取得
if( !empty( $categories ) ) {
foreach( (array)$categories as $val ) {
//$cat_post_id = wp_parse_args( $cat_post_id, $wpdb->get_col( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = $val->cat_ID AND object_id != $post->ID" ) );
$cat_post_id = wp_parse_args( $cat_post_id, $wpdb->get_col( "SELECT object_id FROM $wpdb->term_relationships, $wpdb->term_taxonomy WHERE $wpdb->term_taxonomy.term_id = $val->cat_ID AND $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id AND object_id != $post->ID" ) );
}
shuffle( $cat_post_id );
}
// 同じタグに属する post_id 取得
if( !empty( $tags ) ) {
foreach( (array)$tags as $val ) {
//$tag_post_id = wp_parse_args( $tag_post_id, $wpdb->get_col( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = $val->term_taxonomy_id AND object_id != $post->ID" ) );
$tag_post_id = wp_parse_args( $tag_post_id, $wpdb->get_col( "SELECT object_id FROM $wpdb->term_relationships, $wpdb->term_taxonomy WHERE $wpdb->term_taxonomy.term_taxonomy_id = $val->term_taxonomy_id AND $wpdb->term_taxonomy.term_taxonomy_id = $wpdb->term_relationships.term_taxonomy_id AND object_id != $post->ID" ) );
}
shuffle( $tag_post_id );
}
// 同じタグに属する記事を優先表示させるため wp_parse_args 使わない( wp_parse_args だと同じ値があった時に、配列の後ろが残る形になるため )
//$post_in = wp_parse_args( $tag_post_id, $cat_post_id );
// key は使わず単なる連番なので、array_merge で結合するより + 演算子で結合しちゃった方が速い
//$post_in = array_unique( $tag_post_id + $cat_post_id );
// と思ったけど、array_merge じゃないと要素が消えるパターンがあるから、やっぱり array_merge にしたw
$post_in = array_unique( array_merge( $cat_post_id, $tag_post_id ) );
//$sticky_posts = get_option( 'sticky_posts' );
$args = array(
'posts_per_page'=> 5,
'post__in' => $post_in,
'orderby' => 'post__in',
);
$st_query = new WP_Query($args);
if( $st_query->have_posts() === true ) {
while( $st_query->have_posts() === true ) {
$wp_upload_dir = wp_upload_dir();
$st_query->the_post();
?>
<div class="toc clearfix desktop-related">
<?php
if( isset( $luxe['thumbnail_visible'] ) ) {
$attachment_id = false;
$echo = false;
$post_thumbnail = has_post_thumbnail();
if( $post_thumbnail === false && isset( $luxe['no_img'] ) ) {
$attachment_id = thk_get_image_id_from_url( $luxe['no_img'] );
if( $attachment_id !== false ) {
$post_thumbnail = true;
$echo = true;
$aria_label = 'aria-label="No Imaage"';
}
}
if( $post_thumbnail === true ) { // サムネイル
$thumb = 'thumb100';
$image_id = $attachment_id;
if( $attachment_id === false ) {
$image_id = get_post_thumbnail_id();
}
$image_url = wp_get_attachment_image_src( $image_id, $thumb );
if( isset( $image_url[0] ) && stripos( $image_url[0], '-100x100.' ) !== false ) {
$image_path = str_replace( $wp_upload_dir['baseurl'], $wp_upload_dir['basedir'], $image_url[0] );
if( file_exists( $image_path ) === false ) {
$thumb = 'thumbnail';
}
}
else {
$thumb = 'thumbnail';
}
if( $attachment_id === false ) {
$attachment_id = get_post_thumbnail_id();
$attachment_image = wp_get_attachment_image( $attachment_id );
if( isset( $luxe['amp'] ) ) {
$aria_label = 'aria-hidden="true"';
}
else {
if( !empty( $attachment_image ) && stripos( $attachment_image, 'alt="' ) !== false ) {
$aria_label = substr( $attachment_image, stripos( $attachment_image, 'alt="' ) + 5 );
$aria_label = substr( $aria_label, 0, stripos( $aria_label, '"' ) );
if( empty( $aria_label ) ) {
$aria_label = 'aria-label="' . thk_random_alt_or_aria_label( 'Thumbnail of related posts' ) . '"';
}
else {
$aria_label = 'aria-label="' . $aria_label . '"';
}
}
else {
$aria_label = 'aria-label="' . thk_random_alt_or_aria_label( 'Thumbnail of related posts' ) . '"';
}
}
}
else {
if( isset( $luxe['amp'] ) ) {
$aria_label = 'aria-hidden="true"';
}
else {
$aria_label = 'aria-label="No Image"';
}
}
?><figure class="term"><a href="<?php the_permalink() ?>" <?php echo $aria_label; ?>><?php
if( $echo === true ) {
$attachment_image = wp_get_attachment_image( $attachment_id, $thumb );
echo thk_alt_attribute( $attachment_image, 'Thumbnail of related posts' );
}
else {
//the_post_thumbnail( $thumb );
$get_post_thumbnail = get_the_post_thumbnail( null, $thumb );
echo thk_alt_attribute( $get_post_thumbnail, 'Thumbnail of related posts' );
}
?></a></figure><?php
}
else {
$aria_label = isset( $luxe['amp'] ) ? 'aria-hidden="true"' : 'aria-label="No Image"';
?><figure class="term"><a href="<?php the_permalink() ?>" <?php echo $aria_label; ?>><img src="<?php echo TURI; ?>/images/no-img-100x100.png" alt="No Image" title="No Image" width="100" height="100" /></a></figure>
<?php
}
}
?>
<div class="excerpt">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
</div>
</div>
<?php
}
}
else {
?>
<p class="no-related"><?php echo __( 'No related posts yet.', 'luxeritas' ); ?></p>
<?php
}
wp_reset_postdata();
?>
</div>
CSS
.desktop-related{
padding: 0 !important;
border-top: none !important;
display: flex;
align-items: center;
}
.desktop-related .term img{
padding: 0;
margin: 0 0 5px 0 !important;
border: 1px solid #eee;
border-radius: initial !important;
box-shadow: none;
max-width: 80px;
max-height: 80px;
box-sizing: border-box;
}
.desktop-related .excerpt h3{
margin: 0 !important;
font-size: 1rem !important;
color: #4169e1;
}
.desktop-related .excerpt h3 a{
font-size: 1.8rem !important;
line-height: 2rem !important;
font-weight: 700;
}
次/前のページ
目的:ウィジェット化して自由な場所に置きたい
・luxech > myphpfiles > mobile_next_prev.php
<?php
/**
* Luxeritas WordPress Theme - free/libre wordpress platform
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* @copyright Copyright (C) 2015 Thought is free.
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
* @author LunaNuko
* @link https://thk.kanzae.net/
* @translators rakeem( http://rakeem.jp/ )
*/
global $awesome;
?>
<div id="mobile-pnavi-mother-1">
<div id="mobile-pnavi">
<?php
$prev_post = get_adjacent_post( false, '', true );
if( $prev_post ) {
$thumb = 'thumb75';
$image_id = get_post_thumbnail_id( $prev_post->ID );
$image_url = wp_get_attachment_image_src( $image_id, $thumb );
if( isset( $image_url[0] ) ) {
$image_path = str_replace( $wp_upload_dir['baseurl'], $wp_upload_dir['basedir'], $image_url[0] );
if( file_exists( $image_path ) === false ) {
$thumb = 'thumbnail';
}
}
else {
$thumb = 'thumbnail';
}
$prev_thumb = get_the_post_thumbnail( $prev_post->ID, $thumb );
if( empty( $prev_thumb ) ) $prev_thumb = '<div class="no-img-prev">' . $awesome['text-rotate'] . '</div>';
?>
<div class="prev"><?php previous_post_link( '%link', $prev_thumb . '<div class="ptext"><div class="prev-arrow">' . $awesome['double-arrow-left'] . '<span>前の記事</span></div><div class="ptitle">' . $prev_post->post_title . '</div></div>' ); ?></div>
<?php
}
else {
?>
<div class="prev"></div>
<?php
}
$next_post = get_adjacent_post( false, '', false );
if( $next_post ) {
$thumb = 'thumb75';
$image_id = get_post_thumbnail_id( $next_post->ID );
$image_url = wp_get_attachment_image_src( $image_id, $thumb );
if( isset( $image_url[0] ) ) {
$image_path = str_replace( $wp_upload_dir['baseurl'], $wp_upload_dir['basedir'], $image_url[0] );
if( file_exists( $image_path ) === false ) {
$thumb = 'thumbnail';
}
}
else {
$thumb = 'thumbnail';
}
$next_thumb = get_the_post_thumbnail( $next_post->ID, $thumb );
if( empty( $next_thumb ) ) $next_thumb = '<div class="no-img-next">' . $awesome['text'] . '</div>';
?>
<div class="next"><?php next_post_link( '%link', '<div class="ntext"><div class="next-arrow"><span>次の記事</span>' . $awesome['double-arrow-right'] . '</div><div class="ntitle">' . $next_post->post_title . '</div></div>' . $next_thumb ); ?></div>
<?php
}
else {
?>
<div class="next"></div>
<?php
}
?>
</div></div>
・luxech > myphpfiles > mobile_home_next_prev.php
<?php
/**
* Luxeritas WordPress Theme - free/libre wordpress platform
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* @copyright Copyright (C) 2015 Thought is free.
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
* @author LunaNuko
* @link https://thk.kanzae.net/
* @translators rakeem( http://rakeem.jp/ )
*/
global $awesome;
?>
<div class="grid mobile-pnavi-mother">
<div class="mobile-pnavi-home">
<a href="<?php echo home_url(); ?>">
<?php echo $awesome["text"] . ' 記事一覧へ' ?>
</a>
</div>
<div class="mobile-pnavi">
<?php
$prev_post = get_adjacent_post( false, '', true );
if( $prev_post ) {
$thumb = 'thumb75';
$image_id = get_post_thumbnail_id( $prev_post->ID );
$image_url = wp_get_attachment_image_src( $image_id, $thumb );
if( isset( $image_url[0] ) ) {
$image_path = str_replace( $wp_upload_dir['baseurl'], $wp_upload_dir['basedir'], $image_url[0] );
if( file_exists( $image_path ) === false ) {
$thumb = 'thumbnail';
}
}
else {
$thumb = 'thumbnail';
}
$prev_thumb = get_the_post_thumbnail( $prev_post->ID, $thumb );
if( empty( $prev_thumb ) ) $prev_thumb = '<div class="no-img-prev">' . $awesome['text-rotate'] . '</div>';
?>
<div class="prev"><?php previous_post_link( '%link', $prev_thumb . '<div class="ptext"><div class="prev-arrow">' . $awesome['double-arrow-left'] . '<span>前の記事</span></div><div class="ptitle">' . $prev_post->post_title . '</div></div>' ); ?></div>
<?php
}
else {
?>
<div class="prev"></div>
<?php
}
$next_post = get_adjacent_post( false, '', false );
if( $next_post ) {
$thumb = 'thumb75';
$image_id = get_post_thumbnail_id( $next_post->ID );
$image_url = wp_get_attachment_image_src( $image_id, $thumb );
if( isset( $image_url[0] ) ) {
$image_path = str_replace( $wp_upload_dir['baseurl'], $wp_upload_dir['basedir'], $image_url[0] );
if( file_exists( $image_path ) === false ) {
$thumb = 'thumbnail';
}
}
else {
$thumb = 'thumbnail';
}
$next_thumb = get_the_post_thumbnail( $next_post->ID, $thumb );
if( empty( $next_thumb ) ) $next_thumb = '<div class="no-img-next">' . $awesome['text'] . '</div>';
?>
<div class="next"><?php next_post_link( '%link', '<div class="ntext"><div class="next-arrow"><span>次の記事</span>' . $awesome['double-arrow-right'] . '</div><div class="ntitle">' . $next_post->post_title . '</div></div>' . $next_thumb ); ?></div>
<?php
}
else {
?>
<div class="next"></div>
<?php
}
?>
</div></div>
CSS
.mobile-pnavi-mother{
margin: 0 0 5px 0 !important;
padding: 7px !important;
}
.mobile-pnavi-mother-1{
margin: 0 0 10px 0 !important;
padding: 0 !important;
}
.mobile-pnavi-mother-1 .mobile-pnavi{
margin: 0;
padding: 7px 0;
display: flex;
width: 100%;
border-top: 1px solid #ddd;
border-bottom: 1px solid #ddd;
}
.mobile-pnavi-home{
text-align: center;
margin: 0 0 7px 0;
padding: 0 0 5px 0;
border-bottom: 1px solid #ddd;
}
.mobile-pnavi-home a{
font-size: 1.8rem;
font-weight: 700;
color: #111;
text-decoration: none;
}
.mobile-pnavi-mother .mobile-pnavi{
margin: 0;
padding: 0;
display: flex;
width: 100%;
}
.mobile-pnavi .prev{
width: 50%;
box-sizing: border-box;
border-right: 1px solid #ddd;
}
.mobile-pnavi .prev a{
display: flex;
align-items: center;
font-size: 1.3rem;
font-weight: 700;
line-height: 1.5rem;
color: #111;
text-decoration: none;
}
.mobile-pnavi .prev a .ptext{
margin: 0 5px !important;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
.mobile-pnavi .next{
width: 50%;
box-sizing: border-box;
}
.mobile-pnavi .next a{
display: flex;
align-items: center;
font-size: 1.3rem;
font-weight: 700;
line-height: 1.5rem;
color: #111;
text-decoration: none;
}
.mobile-pnavi .next a .ntext{
margin: 0 5px !important;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
.mobile-pnavi .next a .ntext .next-arrow{
float: initial;
text-align: right;
}
.mobile-pnavi img{
box-sizing: border-box;
width: 50px;
height: 50px;
border: 1px solid #eee;
}
・luxech > myphpfiles > desktop_next_prev.php
<?php
/**
* Luxeritas WordPress Theme - free/libre wordpress platform
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* @copyright Copyright (C) 2015 Thought is free.
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
* @author LunaNuko
* @link https://thk.kanzae.net/
* @translators rakeem( http://rakeem.jp/ )
*/
global $awesome;
?>
<div class="grid desktop-pnavi-mother">
<div class="desktop-pnavi">
<?php
$prev_post = get_adjacent_post( false, '', true );
if( $prev_post ) {
$thumb = 'thumb100';
$image_id = get_post_thumbnail_id( $prev_post->ID );
$image_url = wp_get_attachment_image_src( $image_id, $thumb );
if( isset( $image_url[0] ) ) {
$image_path = str_replace( $wp_upload_dir['baseurl'], $wp_upload_dir['basedir'], $image_url[0] );
if( file_exists( $image_path ) === false ) {
$thumb = 'thumbnail';
}
}
else {
$thumb = 'thumbnail';
}
$prev_thumb = get_the_post_thumbnail( $prev_post->ID, $thumb );
if( empty( $prev_thumb ) ) $prev_thumb = '<div class="no-img-prev">' . $awesome['text-rotate'] . '</div>';
?>
<div class="prev"><?php previous_post_link( '%link', $prev_thumb . '<div class="ptext"><div class="prev-arrow">' . $awesome['double-arrow-left'] . '<span>前の記事</span></div><div class="ptitle">' . $prev_post->post_title . '</div></div>' ); ?></div>
<?php
}
else {
?>
<div class="prev"></div>
<?php
}
$next_post = get_adjacent_post( false, '', false );
if( $next_post ) {
$thumb = 'thumb100';
$image_id = get_post_thumbnail_id( $next_post->ID );
$image_url = wp_get_attachment_image_src( $image_id, $thumb );
if( isset( $image_url[0] ) ) {
$image_path = str_replace( $wp_upload_dir['baseurl'], $wp_upload_dir['basedir'], $image_url[0] );
if( file_exists( $image_path ) === false ) {
$thumb = 'thumbnail';
}
}
else {
$thumb = 'thumbnail';
}
$next_thumb = get_the_post_thumbnail( $next_post->ID, $thumb );
if( empty( $next_thumb ) ) $next_thumb = '<div class="no-img-next">' . $awesome['text'] . '</div>';
?>
<div class="next"><?php next_post_link( '%link', '<div class="ntext"><div class="next-arrow"><span>次の記事</span>' . $awesome['double-arrow-right'] . '</div><div class="ntitle">' . $next_post->post_title . '</div></div>' . $next_thumb ); ?></div>
<?php
}
else {
?>
<div class="next"></div>
<?php
}
?>
</div></div>
CSS
.desktop-pnavi-mother{
margin: 0 0 10px 0 !important;
padding: 10px !important;
}
.desktop-pnavi{
margin: 0;
padding: 0;
display: flex;
width: 100%;
}
.desktop-pnavi .prev{
width: 50%;
box-sizing: border-box;
border-right: 1px solid #ddd;
}
.desktop-pnavi .prev a{
display: flex;
align-items: center;
font-size: 1.8rem;
font-weight: 700;
line-height: 2rem;
color: #4169e1;
text-decoration: none;
}
.desktop-pnavi .prev a .ptext{
margin: 0 5px !important;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
.desktop-pnavi .next{
width: 50%;
box-sizing: border-box;
}
.desktop-pnavi .next a{
display: flex;
align-items: center;
font-size: 1.8rem;
font-weight: 700;
line-height: 2rem;
color: #4169e1;
text-decoration: none;
}
.desktop-pnavi .next a .ntext{
margin: 0 5px !important;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
}
.desktop-pnavi .next a .ntext .next-arrow{
float: initial;
text-align: right;
}
.desktop-pnavi img{
box-sizing: border-box;
width: 80px;
height: 80px;
border: 1px solid #eee;
}
検索結果
目的:検索結果のページのスタイルをほかのリスト系ページと合わせたい
・luxech > search.php
<?php
/**
* Luxeritas WordPress Theme - free/libre wordpress platform
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* @copyright Copyright (C) 2015 Thought is free.
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
* @author LunaNuko
* @link https://thk.kanzae.net/
* @translators rakeem( http://rakeem.jp/ )
*/
global $luxe, $s;
get_header();
if( function_exists( 'thk_search_result' ) === false ) {
function thk_search_result() {
global $s, $wp_query; ?>
<p id="list-title"><?php echo
sprintf( __( 'Search results of [%s]', 'luxeritas' ), esc_html( $s ) ) .
sprintf( __( ' : %s', 'luxeritas' ), $wp_query->found_posts );
?></p><?php
}
}
?>
<input type="hidden" id="search-result" value="<?php echo esc_html( $s ); ?>" />
<?php
if( !empty( $s ) && have_posts() === true ) {
?>
<div id="section"<?php echo $luxe['content_discrete'] === 'indiscrete' ? ' class="grid"' : ''; ?>>
<?php
$luxe = array(
'grid_type' => 'tile',//種別
'grid_cols' => '1',//タイル列数
'content_discrete' => 'discrete',
'thumbnail_visible' => 'true',//サムネイル有無
'thumbnail_is_size_tile' => 'thumbnail',//サムネイルサイズ
'grid_tile_order' => 'ThumbTM',//メタ情報の並び順
'list_post_date_visible' => 'true',
'list_category_meta_visible' => 'true',
'pagination_visible' => 'true',//ページネーション有無
'breadcrumb_view' => '',
);
get_template_part( 'loop-grid' );
?>
</div><!--/#section-->
<?php
}
else {
?>
<article>
<div id="core" class="grid">
<?php
if( $luxe['breadcrumb_view'] === 'inner' ) get_template_part( 'breadcrumb' );
?>
<div itemprop="mainEntityOfPage" id="post">
<h2 id="list-title"><?php echo __( 'No search hits', 'luxeritas' ); ?></h2>
<p><?php echo __('Sorry, the requested post was not found.', 'luxeritas'); ?></p>
</div><!--/#post-->
</div><!--/#core-->
</article>
<?php
}
?>
</main>
<?php thk_call_sidebar(); ?>
</div><!--/#primary-->
<?php echo apply_filters( 'thk_footer', '' ); ?>
・luxech > loop-grid.php
<?php
/**
* Luxeritas WordPress Theme - free/libre wordpress platform
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* @copyright Copyright (C) 2015 Thought is free.
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
* @author LunaNuko
* @link https://thk.kanzae.net/
* @translators rakeem( http://rakeem.jp/ )
*/
global $luxe, $_is, $wp_query;
$observe = 0; // Intersection Observer;
?>
<div id="list" class="<?php echo $luxe['grid_type']; ?>-<?php echo $luxe['grid_cols']; ?>">
<?php
if( $_is['search'] === true ) {
?>
<div id="list" itemscope itemtype="https://schema.org/SearchResultsPage">
<?php
}
else {
?>
<div id="list" class="ngrid">
<?php
}
$b_flag = true;
$s_flag = true;
if( $_is['search'] === true ) {
if( $luxe['content_discrete'] === 'discrete' ) {
if( $b_flag === true ) {
?><div class="toc<?php echo $luxe['content_discrete'] === 'discrete' ? ' grid ' : ' '; ?>clearfix"><?php
if( $luxe['breadcrumb_view'] === 'inner' ) get_template_part( 'breadcrumb' );
thk_search_result();
$b_flag = false;
?></div><?php
}
}
}
// 記事一覧上部ウィジェット
if( is_active_sidebar('posts-list-upper') === true ) {
?>
<div class="posts-list-upper-widget toc<?php echo $luxe['content_discrete'] === 'discrete' ? ' grid ' : ' '; ?>clearfix">
<?php
dynamic_sidebar( 'posts-list-upper' );
?>
</div><!--/.posts-list-upper-widget-->
<?php
}
// カテゴリの説明文
if( $_is['category'] === true && is_paged() === false && isset( $luxe['grid_category_description'] ) ) {
$category_description = get_term_field( 'description', get_query_var( 'cat' ), 'category', 'raw' );
if( !empty( $category_description ) ) {
?>
<div class="category-description toc<?php echo $luxe['content_discrete'] === 'discrete' ? ' grid ' : ' '; ?>clearfix">
<?php
//echo category_description();
echo $category_description;
?>
</div><!--/.category-description-->
<?php
}
}
if( have_posts() === true ) {
$i = 1;
$m = 0;
$b_flag = true;
$first = isset( $luxe['grid_first'] ) ? $luxe['grid_first'] : 0;
$post_count = (int)$wp_query->post_count;
$paged = get_query_var('paged');
if( empty( $paged ) ) $paged = 1;
if( $paged > 1 ) {
$first = 0;
}
elseif( $first >= $post_count ) {
$first = $post_count;
}
if( is_active_sidebar('posts-list-middle') === true ) {
if( isset( $luxe['grid_widget'] ) ) {
// 記事中央ウィジェットの配置
$m = $luxe['grid_widget'];
}
else {
// 記事中央ウィジェットの配置 (自動計算)
$m = (int)floor( round( $post_count / $luxe['grid_cols'] / 2 ) * $luxe['grid_cols'] );
}
}
if( $luxe['breadcrumb_view'] === 'inner' && $i === $first + 1 && $b_flag === true ) {
?>
<div id="breadcrumb-box" class="toc<?php echo $luxe['content_discrete'] === 'discrete' ? ' grid ' : ' '; ?>clearfix">
<?php
get_template_part( 'breadcrumb' );
?>
</div>
<?php
$b_flag = false;
}
while( have_posts() === true ) {
the_post();
// 通常スタイルを表示し終わったら、タイル型/カード型用の <div id="???"> 開始
if( $i === $first + 1 ) {
?>
<div id="<?php echo $luxe['grid_type']; ?>-<?php echo $luxe['grid_cols']; ?>">
<?php
}
?>
<div class="toc<?php echo $luxe['content_discrete'] === 'discrete' ? ' grid ' : ' '; ?>clearfix">
<section>
<?php
if( $luxe['breadcrumb_view'] === 'inner' && $i <= $first && $b_flag === true ) {
get_template_part( 'breadcrumb' );
$b_flag = false;
}
if( $i <= $first ) {
?>
<h2 class="entry-title" itemprop="headline name"><a href="<?php the_permalink(); ?>" class="entry-link" itemprop="url"><?php the_title(); ?></a></h2>
<?php
unset( $luxe['meta_under'] );
get_template_part('meta');
}
// ソースに無駄があるけど、速度的にこっちのが速いので if 分岐多段にした
if( $paged === 1 && $i <= $first ) {
if( !isset( $luxe['sticky_no_excerpt'] ) ) { // sticky_post も含めて全部抜粋で表示する場合
get_template_part('list-excerpt'); // 抜粋表示
}
elseif( is_sticky() === true ) { // sticky_post の場合
get_template_part('list-content'); // 記事全文表示
}
else {
get_template_part('list-excerpt'); // 抜粋表示
}
}
elseif( $luxe['grid_type'] === 'card' ) {
get_template_part('list-excerpt-card'); // グリッドレイアウト:カード型抜粋表示
}
else{
get_template_part('list-excerpt-tile'); // グリッドレイアウト:タイル型抜粋表示
}
?>
</section>
</div><!--/.toc-->
<?php
// 記事一覧の中央ウィジェット
if( $i - $first === $m && function_exists('dynamic_sidebar') === true && is_active_sidebar('posts-list-middle') === true ) {
?>
<div class="posts-list-middle-widget toc<?php echo $luxe['content_discrete'] === 'discrete' ? ' grid ' : ' '; ?>clearfix">
<?php
dynamic_sidebar( 'posts-list-middle' );
?>
</div><!--/.posts-list-middle-widget-->
<?php
}
++$i;
} // end while()
}
else {
?>
<article>
<div id="core" class="grid">
<?php
if( $luxe['breadcrumb_view'] === 'inner' ) get_template_part( 'breadcrumb' );
?>
<div itemprop="mainEntityOfPage" id="post">
<p><?php echo __('Sorry, the requested post was not found.', 'luxeritas'); ?></p>
</div><!--/post-->
</div><!--/#core-->
</article>
<?php
} // end have_posts()
// 記事一覧下部ウィジェット
if( function_exists('dynamic_sidebar') === true && is_active_sidebar('posts-list-under') === true ) {
?>
<div class="posts-list-under-widget toc<?php echo $luxe['content_discrete'] === 'discrete' ? ' grid ' : ' '; ?>clearfix">
<?php
dynamic_sidebar( 'posts-list-under' );
?>
</div><!--/.posts-list-under-widget-->
<?php
}
// ページネーションや SNS ボタンのエリア
$bottom_area = false;
if( ( isset( $luxe['pagination_visible'] ) && apply_filters( 'thk_pagination', true ) === true ) || ( $_is['home'] === true && isset( $luxe['sns_toppage_view'] ) ) ) {
$bottom_area = true;
}
if( $bottom_area === true ) {
?>
<div id="bottom-area" class="toc<?php echo $luxe['content_discrete'] === 'discrete' ? ' grid ' : ' '; ?>clearfix">
<?php
}
// ページネーション
if( isset( $luxe['pagination_visible'] ) ) {
echo apply_filters( 'thk_pagination', null );
}
// SNS ボタン
if( $_is['home'] === true && isset( $luxe['sns_toppage_view'] ) ) {
get_template_part('sns-front');
}
if( $bottom_area === true ) {
?>
</div>
<?php
}
if( isset( $first ) && isset( $post_count ) && $first < $post_count ) {
?>
</div>
<?php
}
?>
</div><!--/#list-->
ディスカッション
コメント一覧
まだ、コメントがありません
本日の人気記事
プロフィール
Author:AIまとめちゃんねる
AIを中心に技術/経済等いろいろなニュースやネタをまとめています。
About & Privacy Policy
最近の人気記事
フォローお願いします
ブログランキング
人気ブログランキング
にほんブログ村
先週の人気記事
お問い合わせ
アンテナサイト
キター(゚∀゚)ー! アンテナ
まとめチェッカー
おまとめ
にけつアンテナ
カオスアンテナ
ブルーアンテナ
相互RSSアンテナ
antenna now
アナグロあんてな