【问题标题】:How to use result of function as link for button如何使用函数的结果作为按钮的链接
【发布时间】:2021-07-23 14:49:49
【问题描述】:

我在我的functions.php 中添加了一个函数,该函数计算我的最新帖子并返回该帖子的链接。现在我想在按下按钮时使用这个函数的结果。所以基本上我有一个名为“最新博客”的按钮,当点击它时应该链接到最新的博客。

函数本身是:

    $args = array(
        'numberposts'     => 1,
        'offset'          => 0,
        'orderby'         => 'post_date',
        'order'           => 'DESC',
        'post_status'     => 'publish' );
    $sorted_posts = get_posts( $args );
    $permalink = get_permalink($sorted_posts[0]->ID);
    return $permalink;
} 

我的主页上有一个按钮,目前有一个硬编码链接:https://www.markt54.be/

我在我的 wordpress 网站中配置 elementor pro 中的所有内容。有人有什么建议吗?

【问题讨论】:

    标签: php wordpress button hyperlink elementor


    【解决方案1】:

    在添加博客/帖子时,在数据库中插入其 SR/索引号 + URL,使用自动递增列

    在加载数据时检查数据库中的最新记录,并在超链接中使用 Last ID' URL,如

    //some PHP Mysql Code
    storing the value of the latest record 's URL in Variable
    
    $url = $row["url"];;
    //some PHP Mysql Code
    
    <a href="www.websitename.com/<?php echo $url; ?>">Button</a>

    【讨论】:

    • 似乎与我目前使用的设置完全不同,我不知道如何在 wordpress 中实现它...
    猜你喜欢
    • 1970-01-01
    • 2012-12-11
    • 1970-01-01
    • 2018-03-09
    • 2016-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-21
    相关资源
    最近更新 更多