我有一個小問題,爲什麼我的內聯PHP代碼不起作用:WordPress的在線PHP不工作
如果我寫我的代碼是這樣的:這是非常醜陋BTW(IMO),它的偉大工程。
<?php
$cat = get_terms('logietype');
?>
<section class="paddings">
<div class="container-full">
<?php
foreach ($cat as $catVal) {
echo "<div class='row'>";
echo "<h2 class='logieheader'>".$catVal->name."</h2>";
$postArg = array('post_type'=>'logie','posts_per_page'=>-1,'order'=>'desc',
'tax_query' => array(
array(
'taxonomy' => 'logietype',
'field' => 'term_id',
'terms' => $catVal->term_id
)
));
$getPost = new wp_query($postArg);
global $post;
if($getPost->have_posts()){
while ($getPost->have_posts()):$getPost->the_post();
echo "<div class='col-md-4 no-padding'>";
echo "<h3 class='logieheader'>".$post->post_title."</h3>";
echo "<p>".$post->post_content."</p>";
echo "</div>";
endwhile;
}
echo '</div>';
}
?>
</div>
</section>
但是當我嘗試這樣的:這是更清潔(IMO),沒有什麼工作:(
<?php
$cat = get_terms('logietype');
?>
<section class="paddings">
<div class="container-full">
<?php foreach ($cat as $catVal): ?>
<div class='row'>
<h2 class='logieheader'><?php $catVal->name ?></h2>
<?php $postArg = array('post_type'=>'logie','posts_per_page'=>-1,'order'=>'desc',
'tax_query' => array(
array(
'taxonomy' => 'logietype',
'field' => 'term_id',
'terms' => $catVal->term_id
)
));
$getPost = new wp_query($postArg);
global $post; ?>
<?php if($getPost->have_posts()): ?>
<?php while ($getPost->have_posts()):$getPost->the_post(): ?>
<div class='col-md-4 no-padding'>
<h3 class='logieheader'><?php $post->post_title ?></h3>
<p><?php $post->post_content ?></p>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
</section>
任何人有任何想法,爲什麼一工程和其他沒有
? !很多感謝
這將是更容易幫助你,如果你(1)告訴我們你想要什麼(2)突出顯示了代碼塊之間的不同之處,(3)解釋了「沒有任何事情發生」的含義,以及(4)包含錯誤日誌中的任何錯誤消息。目前,你的問題面臨着風險,並被關閉。 –
在'<?php $ catVal-> name?>中缺少echo和分號,' post_title?>''和' post_content?>' –