php - 使用 PHP、JQuery 和 wordpress 在单页应用程序中一次显示一篇文章
问题描述
我想在 div 中一次显示一篇文章并替换内容以在单击按钮时显示下一个(相邻)文章的内容。
我目前正在使用 循环浏览帖子wp_query
,但所有帖子都堆叠显示。
query_posts($args);
$temp = $wp_query;
$wp_query = new WP_Query( $args );
$count = $wp_query->post_count;
$i = 1;
if ( $wp_query->have_posts() ) :
while ( $wp_query->have_posts() && $i < 9) : $wp_query->the_post();
?>
我正在提取以下内容:
<?php echo $i?> / <?php echo $count?>
<?php the_title();?>
<?php the_content();?>
我在按钮周围还有一个条件来拉入相邻链接的永久链接,但是当我只需要帖子的 slug 时,它会抓住整个永久链接。我在想象这样的事情,但它不起作用:
$next_slug = get_slug(get_adjacent_post(false, '', false));
解决方案
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php the_title( '<h1>','</h1>' ); ?>
<div class="post-thumbnail"><?php the_post_thumbnail(array(250, 250)); ?> </div>
<div class="entry-content"><?php the_content(); ?></div>
<div class="btn"><?php next_post_link('%link', '%title'); ?></div>
</article>
<?php endwhile; ?>
</div>
推荐阅读
- python - 我可以用不同的消息向不同的收件人发送不同的邮件吗
- excel - Delphi/Excel - 工作表未实例化
- python-3.x - URL 解码和反序列化失败
- ios - 是否可以获得 safari 或其他浏览器当前用于访问网站的当前 URL?
- php - 如何获取主机名以从外部连接而不是“本地主机”
- java - 将图像从表单加载到 RecyclerView
- c++ - 将一个 rapidjson 分配器拥有的内存移动到另一个分配器
- docker - 无法在容器启动时运行自定义脚本
- c# - 从html代码的img标签获取文件名的正则表达式
- swift - 我如何在 Cocoa Touch 库中使用故事板