Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在循环中获取当前WordPress帖子的链接?_Php_Wordpress - Fatal编程技术网

Php 如何在循环中获取当前WordPress帖子的链接?

Php 如何在循环中获取当前WordPress帖子的链接?,php,wordpress,Php,Wordpress,下面是我的循环: <?php if (have_posts()): // This function belowm is responsible for iterating through the posts while (have_posts()): the_post(); ?> <div class="col-md-4"> <h3><?php the_title(); ?&g

下面是我的循环:

<?php if (have_posts()):
    // This function belowm is responsible for iterating through the posts
    while (have_posts()): the_post(); ?>
        <div class="col-md-4">
            <h3><?php the_title(); ?></h3>
            <?php the_content(); ?>
            <?php wp_link_pages(); ?>
            <?php get_post_permalink(); ?>
            <?php edit_post_link(); ?>
        </div>
    <?php
        endwhile; ?>
    <?php
endif; ?>

Get
应显示链接,但这是正在呈现的内容。它没有显示帖子的永久链接


如果你想获得Post Permalink,你应该使用
get\u Permalink($Post\u id)

请尝试以下方法:

<?php if (have_posts()):
    // This function belowm is responsible for iterating through the posts
    while (have_posts()): the_post(); 
    $id = get_the_ID();
?>
        <div class="col-md-4">
            <h3><?php the_title(); ?></h3>
            <?php the_content(); ?>
            <?php wp_link_pages(); ?>
            <?php get_the_permalink($id); ?>
            <?php edit_post_link(); ?>
        </div>
    <?php
        endwhile; ?>
    <?php
endif; ?>

其他答案都不正确
get\u the_permalink()
(您也可以使用
get\u permalink()
,因为它是一个别名)返回数据,而不是ECHO。因此,它永远不会被打印到屏幕上(大多数带有
get\ucode>前缀的WP函数都是这样工作的。)

您有两个选择:

  • 使用
    get_permalink(get_the_ID())
    传递当前帖子ID(如果不在循环中)并回显它
  • 使用
  • permalink(),它将回显permalink(在循环中)
    永久链接()

    这将回显URL,但不会使链接可点击-您需要将其添加到
    返回“post permalink.”,但返回:“如果post不存在,则返回permalink URL或false”。另外,您应该在发布问题之前检查文档。。。我如何获得到帖子的链接?
    <?php if (have_posts()):
        // This function belowm is responsible for iterating through the posts
        while (have_posts()): the_post(); ?>
            <div class="col-md-4">
                <h3><?php the_title(); ?></h3>
                <?php the_content(); ?>
                <?php wp_link_pages(); ?>
                <?php the_permalink(); ?>
                <?php edit_post_link(); ?>
            </div>
        <?php
            endwhile; ?>
        <?php
    endif; ?>
    
    <?php if (have_posts()):
        // This function belowm is responsible for iterating through the posts
        while (have_posts()): the_post(); ?>
            <div class="col-md-4">
                <h3><?php the_title(); ?></h3>
                <?php the_content(); ?>
                <?php wp_link_pages(); ?>
                <?php echo get_permalink(); ?>
                <?php edit_post_link(); ?>
            </div>
        <?php
            endwhile; ?>
        <?php
    endif; ?>
    
    <?php if (have_posts()):
        // This function belowm is responsible for iterating through the posts
        while (have_posts()): the_post(); ?>
            <div class="col-md-4">
                <h3><?php the_title(); ?></h3>
                <?php the_content(); ?>
                <?php wp_link_pages(); ?>
                <a href="<?php the_permalink(); ?>">Click Here</a>
                <?php edit_post_link(); ?>
            </div>
        <?php
            endwhile; ?>
        <?php
    endif; ?>