【发布时间】:2014-02-16 07:51:28
【问题描述】:
我正在尝试构建一个导航栏,列出最新帖子并通过片段标识符超链接对它们的引用,如:
<ul class="nav">
<?php $the_query = new WP_Query( 'showposts=5' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<li class=""><a href="<?php the_title(); ?> "><?php the_title(); ?></a></li>
<?php endwhile;?>
</ul>
在我的页面下方,我有一个锚点,如下所示:
<?php $the_query = new WP_Query( 'showposts=5' ); ?>
<?php while ($the_query ->have_posts()) : $the_query -> the_post(); ?>
<section id="<?php the_title(); ?>">
<br><br><br><br><br><br>
<h3><?php the_title(); ?></h3>
<?php the_excerpt(__('(more…)')); ?>
<?php endwhile;?>
问题是当我在<?php the_title(); ?> 之前添加hastag 时,事情停止工作..
【问题讨论】:
-
“问题是当我添加主题标签 […]” – 你在哪里做的?
-
我在 所以我得到 href="#"
-
然后什么是“不工作”以及如何不工作?标题可能包含空格等,因此不构成有效的
id。我建议使用帖子 id 作为部分 id 和哈希值来链接到该部分(并在其前面加上一个字母以保持兼容性) -
我称之为: 对吗?....我这样做时得到一个空字符串?
-
得到它的工作,不得不使用:post->ID; echo $this_page_id ;?>