我根本不懂PHP,但是我怀疑我的问题对于那些使用PHP的人来说是不是很容易。我的任务很简单,我需要一个最近的帖子插件,以显示我的最后8个帖子,但在相反的顺序。最老的第一个。这是插件的https://wordpress.org/plugins/wp-responsive-recent-post-slider/,我怀疑这是应该添加的模板
<?php
function get_wprps_slider( $atts, $content = null ) {
// setup the query
extract(shortcode_atts(array(
"limit" => '',
"category" => '',
"design" => '',
"show_date" => '',
"show_category_name" => '',
"show_content" => '',
"content_words_limit" => '',
"dots" => '',
"arrows" => '',
"autoplay" => '',
"autoplay_interval" => '',
"speed" => '',
"hide_post" => '',
"post_type" => '',
"show_author" => '',
'show_read_more' => 'true',
), $atts));
// Enqueue required script
wp_enqueue_script( 'wpos-slick-jquery' );
if( $post_type ) {
$postType = $post_type;
} else {
$postType = 'post';
}
if( $hide_post ) {
$hidePost = $hide_post;
} else {
$hidePost = array();
}
if( $show_author ) {
$showAuthor = $show_author;
} else {
$showAuthor = 'true';
}
if( $limit ) {
$posts_per_page = $limit;
} else {
$posts_per_page = '8';
}
if( $category ) {
$cat = $category;
} else {
$cat = '';
}
if( $design ) {
$postdesign = $design;
} else {
$postdesign = 'design-1';
}
if( $show_date ) {
$showDate = $show_date;
} else {
$showDate = 'true';
}
if( $show_category_name ) {
$showCategory = $show_category_name;
} else {
$showCategory = 'true';
}
if( $show_content ) {
$showContent = $show_content;
} else {
$showContent = 'true';
}
if( $content_words_limit ) {
$words_limit = $content_words_limit;
} else {
$words_limit = '20';
}
if( $dots ) {
$dotsv = $dots;
} else {
$dotsv = 'true';
}
if( $arrows ) {
$arrowsv = $arrows;
} else {
$arrowsv = 'true';
}
if( $autoplay ) {
$autoplayv = $autoplay;
} else {
$autoplayv = 'true';
}
if( $autoplay_interval ) {
$autoplayIntervalv = $autoplay_interval;
} else {
$autoplayIntervalv = '3000';
}
if( $speed ) {
$speedv = $speed;
} else {
$speedv = '300';
}
$showreadmore = ( $show_read_more == 'false' ) ? 'false' : 'true';
ob_start();
$posts_type = $postType ;
$orderby = 'post_date';
$order = 'DESC';
$args = array (
'post_type' => $posts_type,
'orderby' => $orderby,
'order' => $order,
'posts_per_page' => $posts_per_page,
'cat' => $cat
);
if(!empty($hidePost)){
$hidePosId = explode(',',$hidePost);
$args['post__not_in'] = $hidePosId;
}
$query = new WP_Query($args);
$post_count = $query->post_count;
if ( $query->have_posts() ) :
?>
<div class="recent-post-slider <?php echo $postdesign; ?>">
<?php
while ( $query->have_posts() ) : $query->the_post();
switch ($postdesign) {
case "design-1":
include('designs/design-1.php');
break;
case "design-2":
include('designs/design-2.php');
break;
case "design-3":
include('designs/design-3.php');
break;
case "design-4":
include('designs/design-4.php');
break;
default:
include('designs/design-1.php');
}
endwhile; ?>
</div><!-- #post-## -->
<?php
endif; ?>
<?php
wp_reset_query();
?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('.recent-post-slider.<?php echo $postdesign; ?>').slick({
dots: <?php echo $dotsv; ?>,
infinite: true,
arrows: <?php echo $arrowsv; ?>,
speed: <?php echo $speedv; ?>,
autoplay: <?php echo $autoplayv; ?>,
autoplaySpeed: <?php echo $autoplayIntervalv; ?>,
slidesToShow: 1,
slidesToScroll: 1,
responsive: [
{
breakpoint: 768,
settings: {
slidesToShow: 1,
slidesToScroll: 1,
infinite: true,
dots: true
}
},
{
breakpoint: 640,
settings: {
slidesToShow: 1,
slidesToScroll: 1
}
},
{
breakpoint: 480,
settings: {
slidesToShow: 1,
slidesToScroll: 1
}
}
]
});
});
</script>
<?php
return ob_get_clean();
}
add_shortcode('recent_post_slider','get_wprps_slider');
function wprps_limit_words($string, $word_limit)
{
$words = explode(' ', $string, ($word_limit + 1));
if(count($words) > $word_limit)
array_pop($words);
return implode(' ', $words);
}
}我删除了最后的一小部分,因为它似乎是管理短码。
提前感谢你的帮助
发布于 2017-05-04 03:39:53
你想要改变
$order = 'DESC';至
$order = 'ASC';这8个帖子已经是极限了。
https://stackoverflow.com/questions/43768481
复制相似问题