admin管理员组

文章数量:1122846

I wrote this code:

<?php
$category_border_color = get_field('category_border_color');
$image = get_field('main_image');
$short_description = get_field('short_description');
$permalink = get_permalink('custom_link');
$more_link_text = get_field('more_link_text');
$event_date_from = get_field('event_date_from');

?>
<?php if ($event_date_from) : ?>
    <div class="col-md-6 post-item">
        <a href="<?php get_the_permalink(); ?>">
            <div class="image-wrap" style="background-image: url(<?php echo $image['sizes']['medium']; ?>);"></div>
            <div class="category_name" style="border-color: <?php echo $category_border_color  ?>"><?php the_title(); ?></div>
        </a>
        <div class="short_text">

            <?php echo $short_description  ?> – <span class="more-link"><a href="<?php get_the_permalink(); ?>"><?php echo $more_link_text  ?></a></span>
        </div>
    </div>
<?php endif; ?>

But the href link isn´t working, in sitecode in frontend it shows: <a href="">Mehr Infos!</a>

So for some reason it doesn´t work the connection to the permalink.
Can someone help please?

Best regards,
Caro

I wrote this code:

<?php
$category_border_color = get_field('category_border_color');
$image = get_field('main_image');
$short_description = get_field('short_description');
$permalink = get_permalink('custom_link');
$more_link_text = get_field('more_link_text');
$event_date_from = get_field('event_date_from');

?>
<?php if ($event_date_from) : ?>
    <div class="col-md-6 post-item">
        <a href="<?php get_the_permalink(); ?>">
            <div class="image-wrap" style="background-image: url(<?php echo $image['sizes']['medium']; ?>);"></div>
            <div class="category_name" style="border-color: <?php echo $category_border_color  ?>"><?php the_title(); ?></div>
        </a>
        <div class="short_text">

            <?php echo $short_description  ?> – <span class="more-link"><a href="<?php get_the_permalink(); ?>"><?php echo $more_link_text  ?></a></span>
        </div>
    </div>
<?php endif; ?>

But the href link isn´t working, in sitecode in frontend it shows: <a href="">Mehr Infos!</a>

So for some reason it doesn´t work the connection to the permalink.
Can someone help please?

Best regards,
Caro

Share Improve this question edited Aug 14, 2024 at 7:30 Rup 4,3904 gold badges28 silver badges29 bronze badges asked Aug 14, 2024 at 7:16 CaroCaro 1
Add a comment  | 

1 Answer 1

Reset to default 1

get_the_permalink() returns the permalink as a string and doesn't echo it. You either need to echo this yourself

<?php echo get_the_permalink(); ?>

as you've got in some of your other <?php tags, or you can use the helper function the_permalink() which does echo

<?php the_permalink(); ?>

the same pattern as you've used for the_title().

Note that these aren't completely equivalent: the_permalink() applies an extra filter, so it's probably worth using that one in case some other code you've got does use the filter.

本文标签: phpWordpress per ACFpermalink is not working