【问题标题】:Wordpress show the_title() if title present如果标题存在,Wordpress 显示 the_title()
【发布时间】:2012-07-07 23:19:57
【问题描述】:

我想要的是:如果帖子有标题,我想显示它

wordpress.org codex可以看到以下例子:

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

还有这个例子:

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

我想做的是在 href 中添加一个带有 the_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

我的头衔

【问题讨论】:

    标签: php wordpress title


    【解决方案1】:
    <?php $permalink = get_permalink(); the_title('<h3><a href="' . $permalink . '">', '</a></h3>'); ?>
    

    【讨论】:

    • “它不起作用”并不能帮助我们确定什么不起作用。请务必提供任何错误消息。
    • 我说!这段代码这样写:mysite.com/?p=1 和 MyTitle 但我想写 MyTitle
    • 另写:mysite.com/?p=1和MyTitle分开,请先自己测试
    • 因为你分节了,the_title($before, $after, $echo)
    • 那句话的第一部分在哪里?...你试过我最新的编辑吗?
    【解决方案2】:

    在循环内the_title() 将回显标题。可以这样写

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

    【讨论】:

      猜你喜欢
      • 2014-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-08
      • 1970-01-01
      • 2013-09-12
      • 1970-01-01
      • 2019-08-13
      相关资源
      最近更新 更多