繁体   English   中英

WordPress:添加“阅读更多”链接以将内容从博客文章/页面拖到首页

[英]Wordpress: Adding 'Read More' links to pulled content from blog posts/pages to front page

为了更好地解释我的问题,我将粘贴在自定义模板的首页中使用的代码开始,该模板从最新博客文章中提取摘录,并在启用了摘录的特定页面中提取摘录。 除了实际添加“ Read More”链接(该链接可链接到最新博客文章或特定页面)之外,所有这些都很好。

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

这是针对页面摘录的。 我坚持要为循环中的“更多阅读”实现什么。 以下是提取最新博客文章的代码。

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

我想做的是在这两个功能的相应帖子/页面上添加“阅读更多”链接。 我对如何使它工作有些困惑,我尝试了一些不同的功能,但它们都没有起作用。

我期待着就这个特殊问题收到您的回音。

詹姆士

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM