php - 阅读更多使用 js 发布 wordpress

标签 php javascript wordpress

嗨,我想用 js 添加阅读更多内容,当点击阅读更多内容时,它将显示有限的内容,它将在同一页面上显示完整的帖子

下面是我使用的代码

     <?php if ( have_posts() ) : ?>

            <?php /* Start the Loop */ ?>
                <?php 
                    if ( get_query_var('paged') ) {
                        $paged = get_query_var('paged');
                    } elseif ( get_query_var('page') ) {
                        $paged = get_query_var('page');
                    } else {
                        $paged = 1;
                    }
                    query_posts( array( 'post_type' => 'post' , 'posts_per_page' => '3' ) );
                ?> <?php while ( have_posts() ) : the_post(); ?>
<div class="post-box img-polaroid row">
<h3 class="title-post text-left span3"><?php the_title(); ?></h3>

<div class="post-par span6 text-left"><?php the_content();?></div>

 <span class="span3 offset3 text-center" style="width:100%; margin:0px;">
 <button class="hear-more"></button>

</span>
</div>
<?php endwhile; ?>
     <?php endif; ?>`

当一些点击阅读更多它会显示完整的帖子......

最佳答案

使用 php 限制发布者:

$length_limit = 1000; //character
echo '<div class="summaryarticle">';
echo mb_substr(the_content(), 0, $length_limit);
echo '</div>';

echo '<input type="button" value="show more..." onclick="$(this).prev().hide(); $(this).next().show();" />';

echo '<div class="fullarticle" style="display:none">';
echo the_content();
echo '</div>';

注意使用页面必须包含jquery。也许是这样。

关于php - 阅读更多使用 js 发布 wordpress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17132087/

相关文章:

php - 使用 POST 将文件从 iOS 发送到 PHP

php - MySQL 网格 : daily sales vs region

PHP 更改页面?

javascript - 如何使用 jQuery 删除类?

javascript - 如何在 Feathers 中创建异步超时错误处理程序?

php - 按下重置按钮后通过关闭旧弹出窗口显示新的弹出窗口并重新显示相同的表单

javascript - 这个值 1522899000000 是什么时间戳格式? ionic 或 AngularJS。我如何在 Java 中使用它

php - 删除子主题中的父主题 Action

php - URL 字符串中包含 "utm_"会破坏 Wordpress 中的 $_GET 变量

jquery - 菜单项无法正常工作