我想使整个div在Wordpress中可以循环点击
我尝试使用the_permalink()将锚链接环绕在div上
<a href="<?php the_permalink(); ?>">
<div class="content-pop-children">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php
if ( has_post_thumbnail() ) :
the_post_thumbnail();
endif;
?>
<header class="entry-hpop">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
<div class="cat-head">
<!-- Output Category and Link to Cat -->
<a href=”<?php echo $category_link ?>”
title=”<?php echo $category_name ?>” >
<?php echo $category_name ?>
</a>
</div> <!-- cat-head -->
<!-- the custom excerpt -->
<?php echo $newsExerp; ?>
</article>
</div> <!-- content-pop-children -->
</a>
我遇到的问题是摘录不可单击,而div的其余部分未正确响应。
此结果https://gyazo.com/eeace52c1803a3c8a5d004435cb704a1
摘录区域不可单击,而其他div不能正确响应,我们将不胜感激
修改
我应该补充一点,我正在创建一个自定义摘录,可以在其中剪裁帖子字符的长度,方法如下:
if ( $arr_posts->have_posts() ) :
while ( $arr_posts->have_posts() ) :
$arr_posts->the_post();
// the custom excerpt
$exerp = get_the_excerpt();
$newsExerp = strip_tags($exerp);
if (strlen($newsExerp) > 500) {
// truncate string
$stringCut = substr($newsExerp, 0, 500);
// make sure it ends in a complete word
$newsExerp = substr($stringCut, 0, strrpos($stringCut, ' ')).'...';
}
然后我用<?php echo $newsExerp; ?>
摘录,我想念东西吗?
答案 0 :(得分:0)
尝试在文章元素中添加锚标记。
<div class="content-pop-children">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<a href="<?php the_permalink(); ?>">
<?php
if ( has_post_thumbnail() ) :
the_post_thumbnail();
endif;
?>
<header class="entry-hpop">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
<div class="cat-head">
<?php echo $category_name ?>
</div>
<!-- cat-head -->
<!-- the custom excerpt -->
<?php echo $newsExerp; ?>
</a>
</article>
</div> <!-- content-pop-children -->
答案 1 :(得分:0)
尝试发布“ content-pop-children”的DOM内容,很可能是您错误地形成了DOM。试试这个
<div class="content-pop-children">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<a href="<?php the_permalink(); ?>">
<?php
if ( has_post_thumbnail() ) :
the_post_thumbnail();
endif;
?>
<header class="entry-hpop">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header>
<div class="cat-head">
<?php echo $category_name ?>
</div>
<!-- cat-head -->
<!-- the custom excerpt wrapped in a class -->
<div class='cat-excerpt'>
<?php echo $newsExerp; ?>
</div>
</a>
</article>
</div> <!-- content-pop-children -->`
.content-pop-children
{
flex: 1 0 30%;
margin: 10px;
border-right: 5px solid #000;
}
.content-pop-children a{
text-decoration:none;
}
<div class="content-pop-children">
<article id="postID">
<a href="https://stackoverflow.com/questions/56928919/how-do-i-make-a-div-clickable-in-wordpress-when-running-loop-query">
<img src="https://placehold.it/300x200">
<header class="entry-hpop">
<h1 class="entry-title">Foo Bar</h1>
</header>
<div class="cat-head">
FOO TITLE
</div>
<!-- cat-head -->
<!-- the custom excerpt -->
<div class="cat-excerpt">
except placed here
</div>
</a>
</article>