Home > Backend Development > PHP Tutorial > wordpress 获取上一篇 下一篇文章参数

wordpress 获取上一篇 下一篇文章参数

WBOY
Release: 2016-06-06 20:51:05
Original
1330 people have browsed it

获取上一篇:previous_post_link(),获取下一篇:next_post_link()

参数:
1、当前文章同一分类下的上下文章
2、上下一篇文章标题、链接、特色图像

如果只是参数1,官方有示例:

<p>
    <?php previous_post_link('上一篇: %link', '%title', 'TRUE'); ?>
</p>
<p>
    <?php next_post_link('下一篇: %link', '%title', TRUE); ?>
</p>
Copy after login
Copy after login

不知道有没有什么方式获取参数2的要求。

wordpress 获取上一篇 下一篇文章参数
上图是要得效果,那两个缩图是WordPress上/下篇文章的特色图像,the_post_thumbnail();调用的 ,下面的标题和链接是上面的代码调用的,特色图像是手动调的,我想要自动调用上/下篇文章的特色图像和链接地址

回复内容:

获取上一篇:previous_post_link(),获取下一篇:next_post_link()

参数:
1、当前文章同一分类下的上下文章
2、上下一篇文章标题、链接、特色图像

如果只是参数1,官方有示例:

<p>
    <?php previous_post_link('上一篇: %link', '%title', 'TRUE'); ?>
</p>
<p>
    <?php next_post_link('下一篇: %link', '%title', TRUE); ?>
</p>
Copy after login
Copy after login

不知道有没有什么方式获取参数2的要求。

wordpress 获取上一篇 下一篇文章参数
上图是要得效果,那两个缩图是WordPress上/下篇文章的特色图像,the_post_thumbnail();调用的 ,下面的标题和链接是上面的代码调用的,特色图像是手动调的,我想要自动调用上/下篇文章的特色图像和链接地址

<?php $current_category=get_the_category();
					$prev_post = get_previous_post($current_category,'');
					$next_post = get_next_post($current_category,'');
				?>
				<div class="previous_post_link fl">
					<?php if (!empty( $prev_post )): ?>
						<a href="<?php%20echo%20get_permalink(%20%24prev_post->ID%20);%20?>"><?php echo get_the_post_thumbnail( $prev_post->ID, '', '' ); ?></a>
						上一篇: <a href="<?php%20echo%20get_permalink(%20%24prev_post->ID%20);%20?>"><?php echo $prev_post->post_title; ?></a>
					<?php endif; ?>
				</div>
				<div class="next_post_link fr">
					<?php if (!empty( $next_post )): ?>
						<a href="<?php%20echo%20get_permalink(%20%24next_post->ID%20);%20?>"><?php echo get_the_post_thumbnail( $next_post->ID, '', '' ); ?></a>
						上一篇: <a href="<?php%20echo%20get_permalink(%20%24next_post->ID%20);%20?>"><?php echo $next_post->post_title; ?></a>
					<?php endif; ?>
				</div>
Copy after login

好人做到底.
自己看着修改吧.

function nav_link_with_thumb(){
         $output = '';
         $prev_post = get_previous_post();
         if ($prev_post){
         	 $output .= get_the_post_thumbnail($prev_post->ID, 'thumbnail');
             $prev_post->filter='sample';
             $output .= 'Previous Post: <a href="'.get_permalink(%20%24prev_post%20).'">'.$prev_post->post_title.'</a>';
         }
         $next_post = get_next_post();
         if ($next_post){
             $output .= get_the_post_thumbnail($next_post->ID, 'thumbnail');
             $next_post->filter='sample';
             $output .= 'Next post: <a href="'.get_permalink(%20%24next_post%20).'">'.$next_post->post_title.'</a>';
         }
         echo $output;
}
Copy after login

能支持下tab吗?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template