How to show complete post by clicking read all button?

Asked

Viewed 1,308 times

1

I am creating a blog and would like to know how to do the following.:

On the home page I display the title, an image and a summary of the post, and when clicking on the "Read All" button, the post is opened completely in another browser window, as in internet blogs.

I am developing as follows: I made the entire layout of a site for a business in my city, more exactly a store of materials for construction, and was also asked for a news portal.

I’m just running tests on an external project, before incorporating it into the site code. I’ll post the code so you can see. I’m very lay with PHP, I’m using Notepad++ to develop my code.

<?php require( 'conectar.php') ?>
<!doctype html>
<html>

    <head>
        <meta charset="utf-8">
        <title>Blog</title>
    </head>

    <body>
        <?php $sql=m ysql_query( " SELECT * FROM postagem ORDER BY data DESC"); $conta=m ysql_num_rows($sql); if($conta <=0 ){ echo '<h2>Nenhuma postagem encontrada.</h2>'; }else{ while($res=m ysql_fetch_array($sql)){ ?>
        <div class="postagem"> <span> <h2><a><?php echo $res['titulo']; ?></a></h2> </span>  <span> <h3><a><?php echo $res['postagem']; ?></a></h3> </span> 
        </div>
        <?php }} ?>
    </body>

</html>

I found the following function.:

function new_excerpt_more($more) {
global $post;
return ‘… <a href=”‘. get_permalink($post->ID) . ‘”>’ . ‘Ler matéria completa &raquo;’ . ‘</a>’;
}
add_filter(‘excerpt_more’, ‘new_excerpt_more’);

I could apply it to my need?

  • 1

    Luis, your question is not related to php, at least not only. Can you explain better what blog you have and how you can change/create HTML on this page? or want to redirect in php by changing the header?

  • 1

    Luis, we need more information to help you. Are you doing this whole blog from scratch without a framework? Have you tried anything? If yes put the code.

  • I’m developing it this way. I made the entire layout of a site for a business in my city, more exactly a store of materials for construction, and also asked for a news portal. I’m just running tests on an external project, before incorporating it into the site code. I’ll post the code so you can see. I’m very lay with PHP, I’m using Notepad++ to develop my code. Sergio, I was unable to understand about this redirection as I said and about the header change. I didn’t even create the Read All button because I didn’t know the structure needed in PHP.

  • Thanks Sergio, I’m beginner here at stackoverflow, I’m grateful for the instructions.

  • You are using Wordpress or found this function by searching on Google?

  • @lfarroco, I thought it would work adapting, I found on google, not use wordpress. It’s not working yet, I can’t open the full post. Could you help me with that? I found this tutorial, but I haven’t been able to understand anything that was explained in it, I just want to do how it was done there, I want to show all the summarized posts in my index.php, and open them when clicked on the Read All button, in a _Blank window with the same design, only with the complete posting.

Show 1 more comment

1 answer

2


I don’t know the structure of your project, but I’ll try to explain.

You have a page where displays all the posts, on this page, in the title of each post as in your code, you added a link that can lead to another page, passing as parameter the id of the post that should be displayed, example:

 <div class="postagem"> <span> 
  <h2>
     <a href="lerPostagem.php?id=<?php echo $res['id'];?>" title="ler postagem completa">
        <?php echo $res['titulo']; ?>
     </a>
  </h2> 

On the page lerPostagem.php, you must take the parameter id via GET and select the post in your database:

$id = $_GET['id'];
$sql = mysql_query("SELECT * FROM postagem WHERE postagem.id = $id");

With the selected post you can display it complements on this page.

Obs: Care must be taken to avoid injection of SQL, consider using prepare statements with PDO or Mysqli.

Obs 2: This is just a didactic explanation, there are N ways to do, would need to know better your project to advise you better.

  • It worked perfectly! Thank you, I was able to understand what should be done, I knew it should be done, but I didn’t know how to do it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.