【问题标题】:Wordpress make entire blog post clickableWordpress 使整个博客文章可点击
【发布时间】:2021-12-28 15:50:58
【问题描述】:

目前我的博文底部有一个小的“查看更多”链接。理想情况下,我想对其进行更改,以便您可以单击<article class="blog-post"> 中的任意位置,它会将您链接到相关文章。

我已经想出了如何做到这一点,因此摘录是可点击的,但无法将其转换为整篇文章

摘录代码 -

function clickable_excerpt( $post ) {
    return '<a href="'. get_the_permalink() .'" class="post">'. $post .'</a>';
}
add_filter( 'get_blog_post', 'clickable_excerpt' );

【问题讨论】:

  • 您使用免费主题吗?可以分享一下主题名吗?
  • 是我做的自定义主题,不过这个应该很通用吧?
  • 如果您编辑 single.php 或显示博客文章的模板文件并将其包裹在文章链接周围会怎样?
  • 对于网格帖子,您必须将此链接放在 foreach 循环下的 archive.php 中,而在单个帖子中您必须放入 single.php/post.php 这个钩子在 foreach 循环下不起作用

标签: html wordpress


【解决方案1】:

试试这个:


 add_filter( 'the_content', 'filter_content' ); 

 function filter_content( $content ) { 
    if ( is_singular('post') ) {

        $content = <a href="'. get_the_permalink() .'" class="post">'. $content .'</a>;

        }

    return $content;
}

如果您可以直接在主题单页模板中执行此操作,则更好,此链接可帮助您识别主题中的正确页面: https://developer.wordpress.org/themes/basics/template-hierarchy/#single-post

【讨论】:

    【解决方案2】:

    在您的主题代码中找到class="grid-item",我在content.php 找到它,然后在文章标签上添加onclick javascript,如下所示

    <article id="post-<?php the_ID(); ?>" <?php post_class('grid-item'); ?> onclick="document.location='<?php the_permalink(); ?>'">
    

    别忘了添加CSS

    article.grid-item {cursor: pointer;}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 2017-09-26
      相关资源
      最近更新 更多