简体   繁体   English

wp安装文件夹外的the_permalink()wordpress

[英]the_permalink() wordpress outside wp installation folder

This is my code to load wordpress posts outside the wordpress installation directory. 这是我的代码,用于在wordpress安装目录之外加载wordpress帖子。 I've found very useful my precedent question about and an old topic that will discuss about this usage of the wp functions in other indipendent php pages. 我发现关于先前的问题非常有用,并且有一个话题将讨论其他独立php页面中wp函数的用法。

PHP query PHP查询

<?php

define('WP_USE_THEMES', FALSE);

require 'portfolio/wp-load.php';

$args = array(
'posts_per_page' => 6,
#'offset' => 0,
#'category' => 'portfolio',
#'category_name' => '',
#'orderby' => 'date',
#'order' => 'DESC',
#'include' => '', 'exclude' => '',
#'meta_key' => '',
#'meta_value' => '',
#'post_type' => 'post', 'post_mime_type' => '',
#'post_parent' => '',
#'author' => '',
#'post_status' => 'publish',
#'suppress_filters' => true
);

$portfolio_items = new WP_Query( $args );

?>

html HTML

<div class="row" id="portfolioPosts">

<?php
if($portfolio_items->have_posts()):
  while($portfolio_items->have_posts()):
    $portfolio_items->the_post(); ?>

<div class="col-sm-12 col-md-4 col-lg-4" id="portfolio-grid-el">
<a class="portfolio-link" href="<?php the_permalink(); ?>">

<?php
if(has_post_thumbnail()):
  the_post_thumbnail('post-thumbnail', ['class' => 'card-img-top post-preview', 'title' => 'Feature image']);
endif;
?>
<h4 class="portfolio-post-title text-uppercase"><?php the_title(); ?></h4>
</a>
</div>
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); wp_reset_query(); ?>
</div>

My question is about the_permalink() function, how i can link it correctly, I've configured wordpress to use my website index that is an indipendent page outside the wp installation directory and in the website root. 我的问题是关于the_permalink()函数,如何正确链接它,我已经配置了wordpress以使用我的网站索引,该网站索引是wp安装目录之外和网站根目录中的独立页面。 For now every time i click on the link, the address is http://localhost:8000/mysite/post-name so I will not be able to display the post. 现在,每次我单击链接时,地址为http://localhost:8000/mysite/post-name所以我将无法显示该帖子。 I want to use a solution where the <a href=""> link is relative to the wordpress installation path or to a page that will accept the post name as an argument and load the content, as i understand by using the loop with a custom query. 我想使用<a href="">链接相对于wordpress安装路径或相对于将接受帖子名称作为参数并加载内容的页面的解决方案,据我了解,通过使用带有自定义查询。 Is it possible? 可能吗?

Use Below code : 使用以下代码:

<?php the_permalink(); ?>

<?php echo get_permalink($portfolio_items->post->ID); ?>

More info 更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM