我想显示少量的文字,当用户来到我的博客,这就是为什么我做了一个“阅读更多”按钮,以显示少量的文字,通过切断长度的文字和按钮是工作正常,直到今天我添加了一个新的职位,通过tinymce编辑器我看到“阅读更多”按钮停止工作。在检查错误时,当我禁用该功能,然后“阅读更多”按钮来活跃和链接后,是工作正常,但我无法切断长度请帮助我解决这个问题。
我正在使用tinymce作为添加新帖子的编辑器。这是index.php文件。
<?php include("includes/db.php"); ?>
<?php include("includes/header.php"); ?>
<!-- Navigation -->
<?php include("includes/navigation.php"); ?>
<!-- Page Content -->
<div class="container">
<div class="row">
<!-- Blog Entries Column -->
<div class="col-md-8">
<?php
$per_page = 3;
if(isset($_GET['page'])) {
$page = $_GET['page'];
}
else {
$page = "";
}
if($page =="" || $page == 1) {
$page_1 = 0;
}
else {
$page_1 = ($page * $per_page) - $per_page;
}
$post_query_count = "SELECT * FROM posts";
$find_count = mysqli_query($connection, $post_query_count);
$count = mysqli_num_rows($find_count);
$count = ceil($count / $per_page);
$query = "SELECT * FROM posts LIMIT $page_1, $per_page";
$select_all_posts_query = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($select_all_posts_query)) {
$post_id = $row['post_id'];
$post_title = $row['post_title'];
$post_user = $row['post_user'];
$post_date = $row['post_date'];
$post_image = $row['post_image'];
$post_content = $row['post_content'];
$post_status = $row['post_status'];
if($post_status == 'published') {
?>
<!-- First Blog Post -->
<h2>
<a href="post.php?p_id=<?php echo $post_id; ?>"><?php echo $post_title; ?></a>
</h2>
<p class="lead">
by <a href="index.php"><?php echo $post_user; ?></a>
</p>
<p><span class="glyphicon glyphicon-time"></span> <?php echo $post_date; ?></p>
<hr>
<a href="post.php?p_id=<?php echo $post_id; ?>">
<img class="img-responsive" src="images/<?php echo $post_image; ?>" alt="">
</a>
<hr>
<?php echo string_length_cutoff($post_content, 320, '........'); ?>
<a class="btn btn-primary" href="post.php?p_id=<?php echo $post_id; ?>">Read More <span class="glyphicon glyphicon-chevron-right"></span></a>
<hr>
<?php
} }
?>
</div>
<!-- Blog Sidebar Widgets Column -->
<?php include("includes/sidebar.php"); ?>
</div>
<!-- /.row -->
<hr>
<ul class="pager">
<?php
for ($i = 1; $i <= $count; $i++) {
if($i == $page) {
echo "<li><a class='active_link' href='index.php?page={$i}'>{$i}</a></li>";
}
else {
echo "<li><a href='index.php?page={$i}'>{$i}</a></li>";
}
}
?>
</ul>
<?php include("includes/footer.php"); ?>
下面的函数存储在functions.php文件中
function string_length_cutoff($post_content, $limit, $subtext = '...') {
global $connection;
$query = "SELECT * FROM posts";
$select_all_posts_query = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($select_all_posts_query)) {
$post_content = $row['post_content'];
}
return (strlen($post_content) > $limit) ? substr($post_content, 0, ($limit-strlen('subtext'))).$subtext : $post_content;
}
一些实际问题的截图
阅读更多按钮不工作
查看更多信息
阅读更多检查
1条答案
按热度按时间exdqitrt1#
我认为不需要数据库查询。把它拿走了。
将函数更改为: