Get_Author_Posts_url()不起作用

时间:2017-12-13 作者:Scott Agirs

全部在单个中。php文件位于Genesis子主题中。

我有一个echo 属于divs 在这两者之间,我在anchors 我正在尝试通过variable, 像这样:

function my_function() {
$author         = get_the_author_meta( $post->post_author );

$author_link    = get_author_posts_url($author);
$author_avatar  = get_avatar_url(get_the_author_meta( $post->post_author ));
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'full\' );
          //..
      echo \'<div>
                // ..
                    <div class="">
                        By <a href="\'.$author_link.\'">Author</a>
                    </div>\'
            </div>
}

genesis();
我尝试过:the_author_posts_url();, get_the_author_meta(\'user_url\');, get_author_posts_url();, get_author_posts_url( get_the_author_meta( \'ID\' ) );每次链接为空或生成

http://localhost/author
不输出特定作者。

单件的完整代码。php在这里:

函数custom\\u entry\\u content(){$author=get\\u the\\u author\\u meta($post->post\\u author);

$author_link    = get_author_posts_url($author);
$author_avatar  = get_avatar_url(get_the_author_meta( $post->post_author ));
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'full\' );

  echo \'<div style="margin-bottom: 50px;position: relative; text-align:center; width:100%;background-image: url(\'.$featured_image[0].\');
          height: 502px;    background-size: cover;
          background-repeat: no-repeat;">
          <div class="post-title-box">
            <h1 class="the-title">
                \'. get_the_title(). \'</h1>
                    </div>

            <div class="post-auth-info">
                <div class="vertical-middle" style="display:inline-block">

                        <div class="">
                            By <a href="\'.$author_link.\'">Author</a>
                        </div>

                        <time class="mk-publish-date" datetime="2017-11-01">
                            <a href="#">Published \' . time_elapsed_string(get_the_date()). \'</a>
                        </time>
                </div>
                <div style="display:inline-block">
                    <a href="\'.$author_link.\'">
                <div>
                            <img alt="" src="\'.$author_avatar.\'" class="img-circle avatar avatar-55 " height="55" width="55" style="height:55px;width:55px">
                </div>
              </a>
                </div>
                    </div>

          </div>\';
}

// Removes Published by and time data from before the post content area
remove_action( \'genesis_entry_header\', \'genesis_post_info\', 12);

add_filter( \'genesis_attr_site-inner\', \'remove_top_padding\');
function remove_top_padding( $attributes ) {
    $attributes[\'class\'] = \'container box nopadding\';
return $attributes;
}

// Adds left padding to content
add_filter( \'genesis_attr_content\', \'padding_left\');
function padding_left( $attributes ) {
    if ( \'full-width-content\' === genesis_site_layout() )
    $attributes[\'class\'] = \'\';
    else
    $attributes[\'class\'] = \'col-md-8 single-post-entry\';
return $attributes;
}

genesis();
非常感谢!

2 个回复
最合适的回答,由SO网友:Scott Agirs 整理而成

感谢所有帮助过我的人,看来主要问题是我没有global $post 在函数内声明。

此外,在调整author\\u id声明后,一切都开始工作,下面是最终代码:

function single_post_entry() {
  global $post;
      $author_id      = $post->post_author;
      $author_link    = get_author_posts_url( $author_id );
      $author_avatar  = get_avatar_url( $author_id );
      $featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'full\' );

      // ..
 echo \'<div>
             By <a href="\' . esc_url( $author_link ) . \'">Author</a>
       </div>\';
}

SO网友:ngearing

get_the_author_meta()

get_author_posts_url()

get_avatar_url()

您错误地使用了这三个功能。请始终首先检查文档。get_the_author_meta() 不需要任何参数,但可以提供希望返回的字段。get_author_posts_url() 需要user\\u id。get_author_posts_url() 这一个更加灵活,可以接受一个user\\u id或各种对象。

下面的代码示例应该可以使用。。。

$author_id = get_the_author_meta( \'ID\' );
$author_link    = get_author_posts_url( $author_id );
$author_avatar  = get_avatar_url( $author_id );
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'full\' );

echo \'<div>
        <div class="">
            By <a href="\' . esc_url( $author_link ) . \'">Author</a>
        </div>
    </div>\';

结束

相关推荐

Pods: Authors to Custom Field

我有200篇博客文章链接到不同的用户。现在我把它们移到了新的Pods自定义字段“author”,因为我不想让其他用户访问我的博客。问题是我必须将每篇文章链接到不同的“作者”自定义字段。是否可以在批量模式下执行此操作,或者我必须编辑每一篇文章?

Get_Author_Posts_url()不起作用 - 小码农CODE - 行之有效找到问题解决它

Get_Author_Posts_url()不起作用

时间:2017-12-13 作者:Scott Agirs

全部在单个中。php文件位于Genesis子主题中。

我有一个echo 属于divs 在这两者之间,我在anchors 我正在尝试通过variable, 像这样:

function my_function() {
$author         = get_the_author_meta( $post->post_author );

$author_link    = get_author_posts_url($author);
$author_avatar  = get_avatar_url(get_the_author_meta( $post->post_author ));
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'full\' );
          //..
      echo \'<div>
                // ..
                    <div class="">
                        By <a href="\'.$author_link.\'">Author</a>
                    </div>\'
            </div>
}

genesis();
我尝试过:the_author_posts_url();, get_the_author_meta(\'user_url\');, get_author_posts_url();, get_author_posts_url( get_the_author_meta( \'ID\' ) );每次链接为空或生成

http://localhost/author
不输出特定作者。

单件的完整代码。php在这里:

函数custom\\u entry\\u content(){$author=get\\u the\\u author\\u meta($post->post\\u author);

$author_link    = get_author_posts_url($author);
$author_avatar  = get_avatar_url(get_the_author_meta( $post->post_author ));
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'full\' );

  echo \'<div style="margin-bottom: 50px;position: relative; text-align:center; width:100%;background-image: url(\'.$featured_image[0].\');
          height: 502px;    background-size: cover;
          background-repeat: no-repeat;">
          <div class="post-title-box">
            <h1 class="the-title">
                \'. get_the_title(). \'</h1>
                    </div>

            <div class="post-auth-info">
                <div class="vertical-middle" style="display:inline-block">

                        <div class="">
                            By <a href="\'.$author_link.\'">Author</a>
                        </div>

                        <time class="mk-publish-date" datetime="2017-11-01">
                            <a href="#">Published \' . time_elapsed_string(get_the_date()). \'</a>
                        </time>
                </div>
                <div style="display:inline-block">
                    <a href="\'.$author_link.\'">
                <div>
                            <img alt="" src="\'.$author_avatar.\'" class="img-circle avatar avatar-55 " height="55" width="55" style="height:55px;width:55px">
                </div>
              </a>
                </div>
                    </div>

          </div>\';
}

// Removes Published by and time data from before the post content area
remove_action( \'genesis_entry_header\', \'genesis_post_info\', 12);

add_filter( \'genesis_attr_site-inner\', \'remove_top_padding\');
function remove_top_padding( $attributes ) {
    $attributes[\'class\'] = \'container box nopadding\';
return $attributes;
}

// Adds left padding to content
add_filter( \'genesis_attr_content\', \'padding_left\');
function padding_left( $attributes ) {
    if ( \'full-width-content\' === genesis_site_layout() )
    $attributes[\'class\'] = \'\';
    else
    $attributes[\'class\'] = \'col-md-8 single-post-entry\';
return $attributes;
}

genesis();
非常感谢!

2 个回复
最合适的回答,由SO网友:Scott Agirs 整理而成

感谢所有帮助过我的人,看来主要问题是我没有global $post 在函数内声明。

此外,在调整author\\u id声明后,一切都开始工作,下面是最终代码:

function single_post_entry() {
  global $post;
      $author_id      = $post->post_author;
      $author_link    = get_author_posts_url( $author_id );
      $author_avatar  = get_avatar_url( $author_id );
      $featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'full\' );

      // ..
 echo \'<div>
             By <a href="\' . esc_url( $author_link ) . \'">Author</a>
       </div>\';
}

SO网友:ngearing

get_the_author_meta()

get_author_posts_url()

get_avatar_url()

您错误地使用了这三个功能。请始终首先检查文档。get_the_author_meta() 不需要任何参数,但可以提供希望返回的字段。get_author_posts_url() 需要user\\u id。get_author_posts_url() 这一个更加灵活,可以接受一个user\\u id或各种对象。

下面的代码示例应该可以使用。。。

$author_id = get_the_author_meta( \'ID\' );
$author_link    = get_author_posts_url( $author_id );
$author_avatar  = get_avatar_url( $author_id );
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'full\' );

echo \'<div>
        <div class="">
            By <a href="\' . esc_url( $author_link ) . \'">Author</a>
        </div>
    </div>\';

相关推荐

Can you set a role as author?

我是WordPress的新手,我正在尝试找出如何最好地设置权限。我想限制人员组只编辑某些页面(IT部门只编辑IT页面,人力资源部门只编辑人力资源页面等等)。据我所知,您取消了角色“编辑其他页面”的权限,然后将页面的作者设置为您要编辑的人。是否有一种设置多个作者的标准方法,或者是否有一种使角色成为作者而不是单个用户的方法?谢谢