Home > database >  clicking on a post link leads to a blank page in php wordpress
clicking on a post link leads to a blank page in php wordpress

Time:06-23

i have been trying to learn php and i am stuck at one point. I created some posts and made them as links but on clicking them, they lead me to a blank page.

Here is the index.php code

  <?php 
 while(have_posts()){
    the_post();?>
    <h2><a href="get_the_permalink()"><?php the_title(); ?></a></h2>
    <?php the_content(); ?>
<?php
 }
?>

Here is the single.php code

<?php 
 while(have_posts()){
    the_post();?>
    <h2><?php the_title(); ?></h2>
    <?php the_content(); ?>
<?php
 }
?>

I changed the href value to another working link and it was working pretty well, the problem maybe with permalink. I went to wordpress dashboard->permalink and tried all kinds of common settings but problem still existed, could someone help me out?

CodePudding user response:

You have to use PHP functions always wrapped inside <?php - ?>

<?php 
 while(have_posts()){
    the_post();?>
    <h2><a href="<?php get_the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php the_content(); ?>
<?php
 }
?>
  • Related