Question

To explain my problem better, I'll begin by pasting the code that I use in a custom template for the front page which pulls the excerpts from the latest blog post and a specific page which has excerpts enabled. It all works great, apart from the actual adding of the "Read More " link which would link to the latest blog post or the specific page.

<?php
  $id=163;

  $post = get_post($id);

  $title = apply_filters('the_title', $post->post_title); ?>
  <h3><?php echo $title; ?></h3>
  <?php $content = apply_filters('get_the_excerpt', $post->post_excerpt);
  echo $content;
?>

This is for the Pages excerpt. I'm stuck to what to implement for the "Read More" in the loop. And below is the code for pulling the latest blog post.

<?php
  $latest_post = new WP_Query("showposts=1");
  if($latest_post->have_posts()) :
?>

<?php
  while($latest_post->have_posts()):
  $latest_post->the_post();
?>

<h4><?php the_title() ?></h4>
  <?php the_excerpt(); ?>

  <?php endwhile ?>
<?php endif ?>

What I would like to do is to add "Read More" links to their respective posts/pages to these two functions. I'm a little bit stuck on how to get this working and I've tried a few different functions and they all did not work.

I look forward to hearing back from you on this particular problem.

James

Was it helpful?

Solution

you can have custom read more link

<?php
 $id=163;

 $post = get_post($id);

 $title = apply_filters('the_title', $post->post_title); ?>
 <h3><?php echo $title; ?></h3>
 <?php $content = apply_filters('get_the_excerpt', $post->post_excerpt);
 echo $content;
 ?>
  <a href="<?php echo  get_permalink() ?>" />Read More </a>
 <?php
 ?>

In the page Excerpt

<?php
  $latest_post = new WP_Query("showposts=1");
  if($latest_post->have_posts()) :
?>

<?php
  while($latest_post->have_posts()):
  $latest_post->the_post();
?>

<h4><?php the_title() ?></h4>
  <?php the_excerpt(); ?>
    <a href="<?php echo  get_permalink() ?>" />Read More </a>
  <?php endwhile ?>
<?php endif ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top