当前位置:首页 >>wordpress使用教程 > 正文

WordPress如何实现列表缩略图显示,WordPress相关文章图文显示

百度: 已收录 | 发布日期:2023-03-19 9:09:07 | 浏览:210 次

要在wordpress中实现文章列表图文显示, 可以使用wordpress插件或者自定义代码实现. 以下是使用插件的方法:

wordpress如何实现列表缩略图显示, wordpress相关文章图文显示

1. 安装插件:在wordpress后台中, 选择"插件"-"添加新插件", 搜索并安装"WP Show Posts"插件.

2. 配置插件:在wordpress后台中, 选择"设置"-"WP Show Posts", 进入插件配置页面. 在配置页面中, 您可以选择需要显示的文章数量、排序方式、排除的分类等. 在"Image"选项中, 选择"Featured Image", 即可启用文章缩略图功能.

3. 在文章列表中显示文章:在需要显示文章列表的页面中, 使用以下代码调用插件:

<?php
if (function_exists('wp_show_posts')) {
wp_show_posts();
}
?>

需要注意的是, 插件会根据您在插件配置页面中的设置来显示文章列表, 所以您需要确保在插件配置页面中正确设置文章数量、排序方式等参数.

除了使用插件, 您也可以使用自定义代码实现. 以下是一个简单的代码示例:

<?php
$args = array(
'post_type' => 'post',
'posts_per_page' => 10,
);
$posts = new WP_Query($args);
if ($posts->have_posts()) :
while ($posts->have_posts()) :
$posts->the_post();
?>
<div class="post">
<div class="post-thumbnail">
<?php the_post_thumbnail(); ?>
</div>
<div class="post-title">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
</div>
<div class="post-excerpt">
<?php the_excerpt(); ?>
</div>
</div>
<?php
endwhile;
endif;
wp_reset_postdata();
?>

将以上代码放置在需要显示文章列表的页面中, 即可实现文章列表图文显示. 需要注意的是, 以上代码仅供参考, 具体实现方法需要根据您的需要进行修改.

99%的人还阅读了:

版权声明:本文由作者:卡卡哥服务器教程网 原创创作,本站内容不允许转载,如发现转载必追究法律责任!! 本文链接:https://yunfuwuqi.chinahzx.cn/wordpress/389.html
本文标签: