首页 文章

如果 Headers 存在,Wordpress会显示the_title()

提问于
浏览
2

我想要的是以下内容:如果帖子有 Headers ,我想展示它

wordpress.org codex中,您可以看到以下示例:

<?php the_title( $before, $after, $echo ); ?>

这个例子:

<?php the_title('<h3>', '</h3>'); ?>

我想要做的是,我在href中添加了带有_permalink的超链接

<?php the_title('<h3><a href=" the_permalink(); ">', '</a></h3>'); ?>

然而,这不起作用 .

换句话说:如何在显示的代码中编写 the_permalink();

我也尝试过:

<?php the_title('<h3><a href="' . the_permalink() . '">', '</a></h3>'); ?>

这导致:

mysite.com/?p=1

我的头衔

2 回答

  • 2
    <?php $permalink = get_permalink(); the_title('<h3><a href="' . $permalink . '">', '</a></h3>'); ?>
    
  • 0

    循环内部 the_title() 将回显 Headers . 你可以用这种方式编写它

    <h3><a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
    

相关问题