最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Unable to retrieve get_author_posts_url

programmeradmin3浏览0评论

So I'm running into issues retrieving the get_author_posts_url() - I'm still in the learning process and want to know why this might be happening:

Here is the code:

<!-- Locate the header.php file under /templates/ -->
<?php include(locate_template('templates/header.php')); ?>

<!-- This is the posts loop, grabs the permalink, the title attributes and the title -->
<?php if (have_posts()) { ?>
    <?php while (have_posts()) { ?>
        <?php the_post(); ?>
        <h2>
            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title() ?></a>
        </h2>
        <div>
            Posted on
            <a href="<?php echo get_permalink(); ?>">
                <!-- Grab the date: .date.php -->
                <time datetime="<?php echo get_the_date('c') ?>" itemprop="datePublished"><?php echo the_date(); ?></time>
            </a>
            By <a href="<?php get_author_posts_url(get_the_author_meta('ID')) ?>"><?php echo get_the_author(); ?></a>
        </div>
    <?php } ?>
<?php } else { ?>
    <p>Sorry, no posts match your criteria.</p>
<?php } ?>

<!-- Locate the footer.php file under /templates/ -->
<?php include(locate_template('templates/footer.php')); ?>

This is the result:

So I'm running into issues retrieving the get_author_posts_url() - I'm still in the learning process and want to know why this might be happening:

Here is the code:

<!-- Locate the header.php file under /templates/ -->
<?php include(locate_template('templates/header.php')); ?>

<!-- This is the posts loop, grabs the permalink, the title attributes and the title -->
<?php if (have_posts()) { ?>
    <?php while (have_posts()) { ?>
        <?php the_post(); ?>
        <h2>
            <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title() ?></a>
        </h2>
        <div>
            Posted on
            <a href="<?php echo get_permalink(); ?>">
                <!-- Grab the date: https://www.php/manual/en/function.date.php -->
                <time datetime="<?php echo get_the_date('c') ?>" itemprop="datePublished"><?php echo the_date(); ?></time>
            </a>
            By <a href="<?php get_author_posts_url(get_the_author_meta('ID')) ?>"><?php echo get_the_author(); ?></a>
        </div>
    <?php } ?>
<?php } else { ?>
    <p>Sorry, no posts match your criteria.</p>
<?php } ?>

<!-- Locate the footer.php file under /templates/ -->
<?php include(locate_template('templates/footer.php')); ?>

This is the result:

Share Improve this question asked Jun 27, 2020 at 11:53 SweSwe 111 bronze badge 3
  • Are you sure that code is what generated that result? There is a " in between </a> and By that isn't in the code, so it seems like maybe you fixed/corrected something? – mozboz Commented Jun 27, 2020 at 11:59
  • @mozboz, looks like I forgot a echo facepalm – Swe Commented Jun 27, 2020 at 12:01
  • hah, well spotted, i was looking and didn't notice :D – mozboz Commented Jun 27, 2020 at 12:03
Add a comment  | 

1 Answer 1

Reset to default 0

Adding answer for reference:

get_author_posts_url(get_the_author_meta('ID')) retrieves the value into the PHP code, it doesn't automatically output it, so you need:

echo get_author_posts_url(get_the_author_meta('ID'));

To output it into the HTML

发布评论

评论列表(0)

  1. 暂无评论