I want to add heading in a code but I don't know how? Can anyone help me? Code is below

Joined
Jan 22, 2023
Messages
1
Reaction score
0
<?php
$catArgs = array(
'category__in' => wp_get_post_categories($post->ID),
'showposts' => 5,//display number of posts
'orderby' =>'rand',//display random posts
'post__not_in' => array($post->ID)
);
$cat_post_query = new WP_Query($catArgs);
if( $cat_post_query->have_posts() ) {
while ($cat_post_query->have_posts()) : $cat_post_query->the_post(); ?>
<li> <a href="<?php the_permalink() ?>"> <?php the_title(); ?></a></li>
<?php endwhile;
wp_reset_query(); } ?>
 
Joined
Jan 30, 2023
Messages
107
Reaction score
13
You can add a heading using HTML tags. Here's an example:

Code:
<?php
$catArgs = array(
'category__in' => wp_get_post_categories($post->ID),
'showposts' => 5,//display number of posts
'orderby' =>'rand',//display random posts
'post__not_in' => array($post->ID)
);
$cat_post_query = new WP_Query($catArgs);
if( $cat_post_query->have_posts() ) {
echo '<h2>Related Posts</h2>'; // Add heading
while ($cat_post_query->have_posts()) : $cat_post_query->the_post(); ?>
<li> <a href="<?php the_permalink() ?>"> <?php the_title(); ?></a></li>
<?php endwhile;
wp_reset_query(); } ?>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top