Wordpress:添加“阅读更多”链接以将博客帖子/页面中的内容提取到首页

时间:2014-01-16 08:40:43

标签: php wordpress permalinks

为了更好地解释我的问题,我将首先粘贴我在首页的自定义模板中使用的代码,其中摘录了最新博客文章和启用了摘录的特定页面的摘录。除了实际添加链接到最新博客文章或特定页面的“阅读更多”链接外,这一切都很有效。

<?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;
?>

这是针对Pages的摘录。我坚持要在循环中为“Read More”实现什么。以下是拉动最新博客文章的代码。

<?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 ?>

我想要做的是在各自的帖子/页面中添加“阅读更多”链接到这两个功能。我有点坚持如何使这个工作,我尝试了一些不同的功能,他们都没有工作。

我期待在这个特殊问题上回复你。

詹姆斯

1 个答案:

答案 0 :(得分:0)

您可以自定义阅读更多链接

<?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
 ?>

在页面摘录

<?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 ?>