【问题标题】:Make section dynamic on index.php (Wordpress)在 index.php (Wordpress) 上使部分动态化
【发布时间】:2017-11-05 15:30:38
【问题描述】:

我正在构建我的第一个 Wordpress 主题,所以我对 Wordpress 和 PHP 都很陌生。我遵循了一堆教程并设法将我现有的网站转换为自定义的 Wordpress 主题。 但是,我的主页 (index.php) 上有一个“关于”部分,我想让它动态化。

我正在关注一个教程,他们使用以下代码在其中一个页面的用户配置文件中添加了传记信息:

<?php the_author_meta( 'description' ); ?>

但这不适用于 index.php 文件。我猜这是因为索引没有任何作者,所以从那里的一位用户那里获得个人简历并没有任何意义……不过我可能完全错了。

有什么建议吗??

【问题讨论】:

    标签: php wordpress dynamic indexing


    【解决方案1】:

    您应该在index.phpthe_author_meta 中使用它,如下所示:

    the_author_meta('description', 12);

    您必须在此处包含author ID 12,这样您就可以确保那里会有描述。你可以通过get_user_by找到作者ID:

    $the_user = get_user_by('email', 'foo@bar.com');
    $the_user_id = $the_user->ID;
    the_author_meta('description', $the_user_id);
    

    【讨论】:

      猜你喜欢
      • 2016-07-01
      • 1970-01-01
      • 2018-01-31
      • 2015-08-12
      • 1970-01-01
      • 1970-01-01
      • 2016-08-02
      • 2017-10-29
      • 1970-01-01
      相关资源
      最近更新 更多