【问题标题】:majuscle to the first character of the custom post title on wordpressmajuscle 到 wordpress 上自定义帖子标题的第一个字符
【发布时间】:2014-08-04 11:44:15
【问题描述】:

我尝试将 wordpress 上自定义帖子标题的第一个字符大写

我在这里找到了这个解决方案:

uppercase issue for title in wordpress

这里是代码:

<a href="<?php the_permalink(); ?>"><?php echo ucfirst(get_the_title());?></a>

它适用于 wordpress 上的普通内容(帖子)。

缺点,我不能在服装贴上使用它!

我也试过这个:

<a href="<?php the_permalink(); ?>"><?php ucfirst(the_title());?></a>

但它不起作用:-(

【问题讨论】:

    标签: php wordpress ucfirst


    【解决方案1】:

    您忘记在第二个示例中回显输出。

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

    更新:

    我刚刚在the wordpress codex 中发现您应该添加一个参数来返回输出。我已经编辑了代码。

    【讨论】:

    • 无错误消息,出现标题但首字母未大写。备注我在存档页面上使用此代码循环显示所有发布的自定义帖子的标题
    【解决方案2】:

    这是我使用的代码:

     <?php 
                          // The Query
                          query_posts( array ( 'post_type' => 'question', 'posts_per_page' => 10 ) );
                          // The Loop
                         while ( have_posts() ) : the_post(); ?>
                            <li>
                                <h2><a href="<?php the_permalink(); ?>"><?php echo ucfirst(the_title('', '', false));?></a></h2>
                                <p class="questionexcerpt"> <?php the_excerpt(); ?> </p>
    
                            </li>
    
                          <?php endwhile; // Reset Query 
                          wp_reset_query();              
                          ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-25
      • 1970-01-01
      相关资源
      最近更新 更多