php 入门主题的相关帖子
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 入门主题的相关帖子相关的知识,希望对你有一定的参考价值。
//
// Related posts title
///////////////////////////
.related-post-title {
color: $black;
display: block;
font-size: 12px;
font-style: italic;
letter-spacing: .5px;
line-height: 1.8rem;
margin-top: 10px;
padding-left: 10px;
padding-right: 10px;
text-decoration: none;
text-transform: lowercase;
&:before {
background-color: #000;
clear: both;
content: "";
display: block;
height: 2px;
margin: 11px auto 10px auto;
text-align: center;
width: 43px;
}
}
/* ## Related Posts
--------------------------------------------- */
.single-post {
.related {
background-color: #F5F4F0;
overflow: hidden;
margin-bottom: 50px;
padding: 30px;
@media only screen and (max-width: 650px) {
padding-bottom: 0;
}
h3 {
font-size: 15px;
margin-bottom: 30px;
text-align: center;
}
}
.related-post {
background-color: $white;
float: left;
padding-bottom: 13px;
text-align: center;
width: 31%;
}
.related-posts-list .related-post:nth-child(2) {
margin-left: 3.5%;
margin-right: 3.5%;
}
}
@media only screen and (max-width: 650px) {
.single-post {
.related-post,
.related-posts-list .related-post:nth-child(2) {
float: none;
margin: 0 auto 30px auto;
width: 353px;
max-width: 100%;
}
}
}
/* # Related Posts
---------------------------------------------------------------------------------------------------- */
@import "base";
@import "title";
<?php
/**
* Adds related posts on single posts
*
* @package KristaRae\Starter
* @since 1.0.0
* @author Krista Rae LLC
* @link https://kristarae.co
* @license GPL
*/
namespace KristaRae\Starter;
add_action( 'genesis_after_entry', __NAMESPACE__ . '\output_related_posts', 12 );
/**
* Output related posts
*
* @since 1.0.0
*
* @return void
*/
function output_related_posts() {
global $do_not_duplicate;
if ( ! is_singular ( 'post' ) ) {
return;
}
$count = 0;
$related = '';
$do_not_duplicate = array();
$tags = wp_get_post_tags( get_the_ID() );
$cats = wp_get_post_categories( get_the_ID() );
// If we have some tags, run the tag query.
if ( $tags ) {
$query = get_related_tags_query( $tags, $count );
$related .= $query['related'];
$count = $query['count'];
}
// If we have some categories and less than 3 posts, run the cat query.
if ( $cats && $count <= 2 ) {
$query = get_related_categories_query( $cats, $count );
$related .= $query['related'];
$count = $query['count'];
}
// End here if we don't have any related posts.
if ( ! $related ) {
return;
}
// Display the related posts section.
echo '<div class="related">';
echo '<h3 class="related-title">You might also like:</h3>';
echo '<div class="related-posts-list" data-columns>' . $related . '</div>';
echo '</div>';
}
/**
* Get the related tags query
*
* @since 1.0.0
*
* @param $tags
* @param $count
*
* @return array|void
*/
function get_related_tags_query( $tags, $count ) {
global $do_not_duplicate;
if ( ! $tags ) {
return;
}
$postIDs = array( get_the_ID() );
foreach ( $tags as $tag ) {
$tagID[] = $tag->term_id;
}
$tax_query = array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array(
'post-format-link',
'post-format-status',
'post-format-aside',
'post-format-quote'
),
'operator' => 'NOT IN'
)
);
$args = array(
'tag__in' => $tagID,
'post__not_in' => $postIDs,
'showposts' => 3,
'ignore_sticky_posts' => 1,
'tax_query' => $tax_query,
);
$related = '';
$tag_query = new \WP_Query( $args );
if ( $tag_query->have_posts() ) {
while ( $tag_query->have_posts() ) {
$tag_query->the_post();
$do_not_duplicate[] = get_the_ID();
$count++;
// $title = genesis_truncate_phrase( get_the_title(), 35 );
$title = get_the_title();
$related .= '<div class="related-post">';
$related .= '<a class="related-image" href="' . get_permalink() . '" rel="bookmark" title="Permanent Link to ' . $title . '">' . genesis_get_image( array( 'size' => 'featured-post' ) ) . '</a>';
$related .= '<a class="related-post-title" href="' . get_permalink() . '" rel="bookmark" title="Permanent Link to ' . $title . '">' . $title . '</a>';
$related .= '</div>';
}
}
wp_reset_postdata();
$output = array(
'related' => $related,
'count' => $count
);
return $output;
}
/**
* Get the related categories query
*
* @since 1.0.0
*
* @param $cats
* @param $count
*
* @return array|void
*/
function get_related_categories_query( $cats, $count ) {
global $do_not_duplicate;
if ( ! $cats ) {
return;
}
$postIDs = array_merge( array( get_the_ID() ), $do_not_duplicate );
$catIDs = array();
foreach ( $cats as $cat ) {
if ( 3 == $cat ) {
continue;
}
$catIDs[] = $cat;
}
$showposts = 3 - $count;
$tax_query = array(
array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array(
'post-format-link',
'post-format-status',
'post-format-aside',
'post-format-quote'
),
'operator' => 'NOT IN'
)
);
$args = array(
'category__in' => $catIDs,
'post__not_in' => $postIDs,
'showposts' => $showposts,
'ignore_sticky_posts' => 1,
'orderby' => 'rand',
'tax_query' => $tax_query,
);
$related = '';
$cat_query = new \WP_Query( $args );
if ( $cat_query->have_posts() ) {
while ( $cat_query->have_posts() ) {
$cat_query->the_post();
$count++;
// $title = genesis_truncate_phrase( get_the_title(), 35 );
$title = get_the_title();
$related .= '<div class="related-post">';
$related .= '<a class="related-image" href="' . get_permalink() . '" rel="bookmark" title="Permanent Link to ' . $title . '">' . genesis_get_image( array( 'size' => 'featured-post' ) ) . '</a>';
$related .= '<a class="related-post-title" href="' . get_permalink() . '" rel="bookmark" title="Permanent Link to ' . $title . '">' . $title . '</a>';
$related .= '</div>';
}
}
wp_reset_postdata();
$output = array(
'related' => $related,
'count' => $count
);
return $output;
}
以上是关于php 入门主题的相关帖子的主要内容,如果未能解决你的问题,请参考以下文章
php 禁用HTML5的Genesis和Studiopress主题的帖子信息
php Quick Singleton类将包含在WordPress插件(或主题functions.php文件)中,它将创建一个简单的Person帖子类型并显示