如何在php中插入html,然后在html中插入php
我想在PHP中插入HTML,然后在HTML中插入PHP。我不知道我该怎么做如何在php中插入html,然后在html中插入php,php,html,wordpress,Php,Html,Wordpress,我想在PHP中插入HTML,然后在HTML中插入PHP。我不知道我该怎么做 <div class="popular-posts"> <?php $popularpost = new WP_Query( array( 'posts_per_page' => 3, 'meta_key' => 'wpb_post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC
<div class="popular-posts">
<?php
$popularpost = new WP_Query( array( 'posts_per_page' => 3, 'meta_key' => 'wpb_post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC' ) );
while ( $popularpost->have_posts() ) : $popularpost->the_post();
<?php echo get_the_post_thumbnail( $post_id, 'full' ); ?>
<a href="<?php echo get_permalink(); ?>"><?php the_title() ?></a>
endwhile;
?>
</div>
结束时;
?>
试试这个:
<div class="popular-posts">
<?php
$popularpost = new WP_Query( array( 'posts_per_page' => 3, 'meta_key' => 'wpb_post_views_count', 'orderby' => 'meta_value_num', 'order' => 'DESC' ) );
while ( $popularpost->have_posts() ) : $popularpost->the_post();
echo get_the_post_thumbnail( $post_id, 'full' ); ?>
<a href="<?= get_permalink(); ?>"><?= the_title() ?></a>
<?php
endwhile;
?>
</div>
首先,文件扩展名必须是(点)php格式 要在PHP中插入HTML,只需使用“echo”编写即可。即:
<html>
<body>
<p>write in html</p>
<?php
echo '<h1>Write in PHP</h1>';
?>
</body>
</html>
用html编写
不能在HTML文件中编写PHP代码。但是您可以在HTML元素中编写PHP代码,文件扩展名必须是(点)PHP。即:
<html>
<body>
<?php
$color = 'yellow';
?>
<h1 style="color:<?php echo $color; ?>">Example</h1>
</body>
</html>
您没有关闭第一个打开的PHP标记,然后又打开了另一个PHP。。。而且您没有打开最后一条语句“endwhile;”
在HTML中使用PHP的一般语法是
<html>
<head>
</head>
<body>
<?php
// Your PHP Code
?>
</body>
</html>
在PHP中使用HTML
<?php
//Your PHP Code
?>
<!-- Your HTML Tags -->
<?php
?>
或者你也可以这样尝试
<?php
//Your PHP Code
echo "<ul><li>Some Text</li></ul>";
?>
你用谷歌搜索过它了吗?过一会儿关闭php标记($popularpost->have_posts()):$popularpost->the_post();?>完美的谢谢:)
<?php
//Your PHP Code
echo "<ul><li>Some Text</li></ul>";
?>