Php #u摘录没有';t出现-woocommerce/wordpress
HMTL原始渲染:Php #u摘录没有';t出现-woocommerce/wordpress,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,HMTL原始渲染: <div class="col-md-4"> <div class="row"> <a href="http://localhost/PHP/wordpress/3-blog-post/">3 - Blog Post</a> </div> <div class="row"> <img width="150" h
<div class="col-md-4">
<div class="row">
<a href="http://localhost/PHP/wordpress/3-blog-post/">3 - Blog Post</a>
</div>
<div class="row">
<img width="150" height="150" src="http://localhost/PHP/wordpress/wp-content/uploads/2017/04/imagem-principal-150x150.jpg" class="attachment-thumbnail size-thumbnail wp-post-image" alt="" srcset="http://localhost/PHP/wordpress/wp-content/uploads/2017/04/imagem-principal-150x150.jpg 150w, http://localhost/PHP/wordpress/wp-content/uploads/2017/04/imagem-principal-300x300.jpg 300w, http://localhost/PHP/wordpress/wp-content/uploads/2017/04/imagem-principal-768x768.jpg 768w, http://localhost/PHP/wordpress/wp-content/uploads/2017/04/imagem-principal.jpg 900w" sizes="(max-width: 150px) 100vw, 150px" />
</div>
</div>
设置后的HTML_postdata($post)
贝姆·文多·奥·沃德普莱斯。Esseéo seu primeiro post。伊迪特-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-欧-!
奇怪的事情: 守则:
<div class="container">
<div class="row">
<?php
$args = array( 'numberposts' => '3' );
$recent_posts = wp_get_recent_posts( $args );
foreach($recent_posts as $post)
{
?><div class="col-md-4">
<div class="row">
<a href="<?php echo get_the_permalink($post['ID']); ?>">
<?php echo $post['post_title']; ?>
</a>
</div>
<div class="row">
<?php echo get_the_post_thumbnail($post['ID'], 'thumbnail'); ?>
<?php
$my_excerpt = get_the_excerpt($post['ID']);
if ( '' != $my_excerpt ) {
// Some string manipulation performed
}
echo $my_excerpt // Outputs the processed value to the page
?>
</div>
</div><?php
}
wp_reset_query();
?>
</div>
</div>
</br>
</br>
<div class="container">
<div class="row">
<?php
$args = array( 'numberposts' => '3' );
$recent_posts = wp_get_recent_posts( $args );
foreach($recent_posts as $post) { ?>
<div class="col-md-4">
<div class="row">
<a href="<?php echo get_the_permalink($post['ID']) ?>">
<?php echo $post['post_title'] ?>
</a>
</div>
<div class="row">
<?php echo get_the_post_thumbnail($post['ID'], 'thumbnail'); ?>
</div>
<div class="row">
<?php
$my_excerpt = get_the_excerpt($post['ID']);
if ( '' != $my_excerpt ) {
// Some string manipulation performed
}
echo $my_excerpt // Outputs the processed value to the page
?>
</div>
</div>
<?php
}
wp_reset_query();
?>
</div>
</div>
当我更改代码的位置并删除标题和缩略图时,代码运行良好:
<?php
$args = array( 'numberposts' => '3' );
$recent_posts = wp_get_recent_posts( $args );
foreach($recent_posts as $post) { ?>
<?php
$my_excerpt = get_the_excerpt($post['ID']);
if ( '' != $my_excerpt ) {
// Some string manipulation performed
}
echo $my_excerpt // Outputs the processed value to the page
?>
</div>
</div>
<?php
}
wp_reset_query();
?>
我在wordpress/woocommerce页面中调用了最近的帖子,但是当我调用摘录时,它没有出现,标题和缩略图都可以。我整天都在努力,但我不知道会发生什么。当我用一个简单的单词更改“echo$my_摘录”时,它就起作用了。问题应该是当我将内容放入数组时。如您所见,我遵循了文档:
例子
get_可使用_extract()在变量中检索和存储值,而无需将其输出到页面
<?php
$my_excerpt = get_the_excerpt();
if ( '' != $my_excerpt ) {
// Some string manipulation performed
}
echo $my_excerpt; // Outputs the processed value to the page
?>
我的代码:
<?php
$args = array( 'numberposts' => '3' );
$recent_posts = wp_get_recent_posts( $args );
foreach($recent_posts as $post) { ?>
<div class="col-md-4">
<div class="row">
<a href="<?php echo get_permalink($post['ID']) ?>">
<?php echo $post['post_title'] ?>
</a>
</div>
<div class="row">
<?php echo get_the_post_thumbnail($post['ID'], 'thumbnail'); ?>
<?php
$my_excerpt = get_the_excerpt();
if ( '' != $my_excerpt ) {
// Some string manipulation performed
}
echo $my_excerpt // Outputs the processed value to the page
?>
</div>
</div>
<?php
}
wp_reset_query();
?>
</div>
</div>
编辑:我已更改了您的代码,请尝试使用此代码
<?php
$args = array( 'numberposts' => '3' );
$recent_posts = wp_get_recent_posts( $args );
foreach($recent_posts as $post)
{
setup_postdata( $post ); // Edit: This will force wordpress to setup the data
?><div class="col-md-4">
<div class="row">
<a href="<?php echo get_the_permalink($post['ID']); ?>">
<?php echo $post['post_title']; ?>
</a>
</div>
<div class="row">
<?php echo get_the_post_thumbnail($post['ID'], 'thumbnail'); ?>
<?php
$my_excerpt = get_the_excerpt($post['ID']);
if ( '' != $my_excerpt ) {
// Some string manipulation performed
}
echo $my_excerpt // Outputs the processed value to the page
?>
</div>
</div><?php
}
wp_reset_query();
?>
试试这个。我已经提供了post id以便您获取摘录
<?php
$my_excerpt = get_the_excerpt($post['ID']);
if ( '' != $my_excerpt ) {
// Some string manipulation performed
}
echo $my_excerpt // Outputs the processed value to the page
?>
好吧,经过大量的选择、测试、反馈和研究,我找到了一种方法 谢谢大家 我的最终代码:
<!-- Testando novo formato -->
<p class="display-4" style="text-align:center">Testando - Posts Recentes</p>
<div class="container">
<div class="row">
<?php
query_posts( array('posts_per_page'=>3) );
while ( have_posts() ) : the_post();
?>
<div class="col-md-4">
<div class="card" style="width: 20rem; margin-bottom:3rem; margin-top:3rem;">
<img class="card-img-top img-fluid" src="<?php the_post_thumbnail(); ?>">
<div class="card-block">
<h4 class="card-title"><?php the_title(); ?></h4>
<p class="card-text">
<?php
the_excerpt();
?>
</p>
<a class="btn btn-primary" href="<?php the_permalink(' ') ?>">Ler o post</a>
</div>
</div>
</div>
<?php
endwhile;
wp_reset_query(); // resets main query
?>
</div>
</div>
Testando-贴子
">
您没有像使用其他函数一样提供post id来获取摘录。由于您没有使用wordpress的正式循环机制,因此需要手动提供id。请参阅我的答案。请在foreach启动安装程序后写入此项。\u postdata($post);只要检查一下就可以了。屏幕截图是相当无用的。CSS或其他奇怪的东西可能会隐藏您的输出。相反,请执行“查看源代码”并向我们显示呈现的HTML。好的,在添加设置后,$postdata($post)会出现摘录,但它会带来“Hello Word”“发布所有内容。我将发布呈现的html。只需一分钟。无需/不使用setup\u postdata
-这与您认为的不一样。我更改了代码的位置并删除了标题和缩略图,这次出现了摘录。这就是问题所在。更改get_permalink以获得_permalink,它将正常工作代码正常工作,问题似乎就在这里。当我改变位置时,一切都会显示出来。你能试试我粘贴过的代码吗?Wordpress有两种功能,一种是返回,另一种是回显。所以请尝试一下。会有用的,我做到了。没有什么变化。看看我上面编辑的帖子,最后你使用了正式的循环机制+1.
<!-- Testando novo formato -->
<p class="display-4" style="text-align:center">Testando - Posts Recentes</p>
<div class="container">
<div class="row">
<?php
query_posts( array('posts_per_page'=>3) );
while ( have_posts() ) : the_post();
?>
<div class="col-md-4">
<div class="card" style="width: 20rem; margin-bottom:3rem; margin-top:3rem;">
<img class="card-img-top img-fluid" src="<?php the_post_thumbnail(); ?>">
<div class="card-block">
<h4 class="card-title"><?php the_title(); ?></h4>
<p class="card-text">
<?php
the_excerpt();
?>
</p>
<a class="btn btn-primary" href="<?php the_permalink(' ') ?>">Ler o post</a>
</div>
</div>
</div>
<?php
endwhile;
wp_reset_query(); // resets main query
?>
</div>
</div>