플러그인 없이 WordPress에서 최신, 인기 및 무작위 기사를 호출하는 방법

藏色散人
풀어 주다: 2020-01-11 09:36:35
원래의
2552명이 탐색했습니다.

플러그인 없이 WordPress에서 최신, 인기 및 무작위 기사를 호출하는 방법

플러그인 없이 WordPress에서 최신 인기 기사를 무작위로 호출하는 방법은 무엇입니까?

플러그인이 없는 WordPress는 최신의 인기 있는 임의 기사 예제 코드를 호출합니다

권장: "wordpress tutorial"

플러그인이 없는 WordPress는 최신의 인기 있는 임의 기사, 특정 구현 코드를 호출합니다. 관심 있는 친구들은 다음과 같습니다. 참고로 뉴스를 호출하는 모든 분들께 도움이 되기를 바랍니다

최신 기사 호출:

코드는 다음과 같습니다:

<ul> 
<?php $post_query = new WP_Query(‘showposts=10′); 
while ($post_query->have_posts()) : $post_query->the_post(); 
$do_not_duplicate = $post->ID; ?> 
<li><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></li> 
<?php endwhile;?> 
</ul>
로그인 후 복사

인기 기사 호출:

코드는 다음과 같습니다.

<ul> 
<?php 
$post_num = 10; // 设置调用条数 
$args = array( 
‘post_password’ => ”, 
‘post_status’ => ‘publish’, // 只选公开的文章. 
‘post__not_in’ => array($post->ID),//排除当前文章 
‘caller_get_posts’ => 1, // 排除置顶文章. 
‘orderby’ => ‘comment_count’, // 依评论数排序. 
‘posts_per_page’ => $post_num 
); 
$query_posts = new WP_Query(); 
$query_posts->query($args); 
while( $query_posts->have_posts() ) { $query_posts->the_post(); ?> 
<li><a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”><?php the_title(); ?></a></li> 
<?php } wp_reset_query();?> 
</ul>
로그인 후 복사

임의의 기사 호출:

코드는 다음과 같습니다.

<ul> 
<?php 
global $post; 
$postid = $post->ID; 
$args = array( ‘orderby’ => ‘rand’, ‘post__not_in’ => array($post->ID), ‘showposts’ => 10); 
$query_posts = new WP_Query(); 
$query_posts->query($args); 
?> 
<?php while ($query_posts->have_posts()) : $query_posts->the_post(); ?> 
<li><a href=”<?php the_permalink(); ?>” rel=”bookmark” title=”<?php the_title_attribute(); ?>”><?php the_title(); ?></a></li> 
<?php endwhile; ?> 
</ul>
로그인 후 복사

위 내용은 플러그인 없이 WordPress에서 최신, 인기 및 무작위 기사를 호출하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!