如何将WordPress的帖子内容格式化为html格式
我的网站运行在WordPress服务器上,我正在使用WordPress数据库提取一些数据供我自定义使用。我想知道如何将我的帖子内容从WordPress的post表转换成格式良好的html格式,就像java或NodeJS中WordPress rest api返回的一样 请使用如何将WordPress的帖子内容格式化为html格式,html,wordpress,Html,Wordpress,我的网站运行在WordPress服务器上,我正在使用WordPress数据库提取一些数据供我自定义使用。我想知道如何将我的帖子内容从WordPress的post表转换成格式良好的html格式,就像java或NodeJS中WordPress rest api返回的一样 请使用apply_filters功能以格式良好的方式显示内容 使用- 而不是- <?php echo $post->post_content; ?> 希望,这可能对您有所帮助。编辑 下面是另一个回答你问题
apply_filters
功能以格式良好的方式显示内容
使用-
而不是-
<?php echo $post->post_content; ?>
希望,这可能对您有所帮助。编辑下面是另一个回答你问题的例子。
我想你要找的是。它的工作方式是创建一个要从数据库中提取的对象数组,然后循环通过它们显示在屏幕上。我正在检索一个帖子类型,它只有一个没有内容的缩略图 在这里的这个例子中,我创建了一个名为
$args
的数组来获取post\u type=>portfolio\u item
,我希望每页显示30个项目posts=>30个。然后,我将通过调用WP_query的新实例来运行查询,调用参数并将其放置在变量上<代码>$thew_query=newwp_query($args)代码>
如果查询返回我想要获取的任何项目,在本例中为post类型<代码>while($the_query->have_posts()):$the_query->the_post()代码>。在循环内部,您可以以任何方式、形状或形式设置输出样式
循环结束后,不要忘记使用wp_reset_postdata()代码>或者它可以中断将来的查询类
<?php
// Define our WP Query Parameters
$args = array(
'post_type' => 'portfolio_item',
'posts-per-page' => 30,
);
$the_query = new WP_Query( $args );
// Start our WP Query
while ( $the_query -> have_posts() ) : $the_query -> the_post();
// Display the Post Feature Image and Post Title ?>
<div <?php post_class( 'col-xs-12 col-sm-6 col-lg-4 mb-2 portfolio' ); ?> data-cat="logo">
<div class="portfolio-wrapper d-flex">
<?php the_post_thumbnail( 'large', ['class' => 'align-self-center mx-auto jbox-img img-thumbnail'] ); ?>
<div class="label">
<div class="label-text">
<span class="text-category"><?php the_title() ?></span>
</div>
<div class="label-bg"></div>
</div>
</div>
</div>
<?php
// Repeat the process and reset once it hits the limit
endwhile;
wp_reset_postdata();
?>
您能否提供您的代码,即您如何显示内容,以便我能更好地帮助您。但我也想用另一种语言(如nodeJs)格式化内容,并从wordpress数据库提取数据。
<?php
// Define our WP Query Parameters
$args = array(
'post_type' => 'portfolio_item',
'posts-per-page' => 30,
);
$the_query = new WP_Query( $args );
// Start our WP Query
while ( $the_query -> have_posts() ) : $the_query -> the_post();
// Display the Post Feature Image and Post Title ?>
<div <?php post_class( 'col-xs-12 col-sm-6 col-lg-4 mb-2 portfolio' ); ?> data-cat="logo">
<div class="portfolio-wrapper d-flex">
<?php the_post_thumbnail( 'large', ['class' => 'align-self-center mx-auto jbox-img img-thumbnail'] ); ?>
<div class="label">
<div class="label-text">
<span class="text-category"><?php the_title() ?></span>
</div>
<div class="label-bg"></div>
</div>
</div>
</div>
<?php
// Repeat the process and reset once it hits the limit
endwhile;
wp_reset_postdata();
?>