简体   繁体   English

使整个单元格可点击

[英]Making entire cell clickable

I have a div container with a title and content as shown in the picture. 我有一个带标题和内容的div容器,如图所示。

在此处输入图片说明

Here is the markup: 这是标记:

$output .= '<h1 class="list_title">';
    $output .= '<a href="' . get_permalink () . '">'.the_title ('','',false) . '</a>';                  
$output .= '</h1>';

$output .= '<div class="list_content">';
    $output .= '<a href="' . get_permalink () . '">';
        $output .= wp_trim_words ($post->post_content, $content_length );
    $output .= '</a>';
$output .= '</div>';

In these two components, I added get_permalink so that users can click either the title or the content to go to the post link. 在这两个组件中,我添加了get_permalink以便用户可以单击标题或内容以转到帖子链接。

However, I am trying to make it so that user can click anywhere in the cell (such as the empty space as B to go to the link. 但是,我试图做到这一点,以便用户可以单击单元格中的任何位置(例如B的空白区域以转到链接)。

Can anyone tell me how I can make the whole cell clickable instead just the title or content? 谁能告诉我如何使整个单元格可单击,而不仅仅是标题或内容?

Put div inside <a> and maybe add display: block to <a> : 把里面的div <a>也许添加display: block<a>

$output .= '<a href="' . get_permalink () . '">';
    $output .= '<div class="list_content">';
        $output .= wp_trim_words ($post->post_content, $content_length );
    $output .= '</div>';
$output .= '</a>';

What you want to do is wrap the whole <div> in an <a> tag; 您要做的是将整个<div>包装在<a>标记中;

$output .= '<a href="' . get_permalink () . '">'.the_title ('','',false) . '</a>';  
$output .= '<h1 class="list_title">';

$output .= '<div class="list_content">';
    $output .= '<a href="' . get_permalink () . '">';
        $output .= wp_trim_words ($post->post_content, $content_length );
$output .= '</div>';
    $output .= '</a>';

I removed the <h22> tag, it was empty. 我删除了<h22>标记,它为空。

Reverse the order of your tags. 颠倒标签的顺序。 The <div> should be inside the <a> . <div>应该在<a>

 $output. = '<a href="'.get_permalink().'">'; $output. = '<div class="list_content">'; $output. = wp_trim_words($post - > post_content, $content_length); $output. = '</a>'; $output. = '</div>'; 

That means that the whole div is a link . 这意味着整个div是一个链接

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

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