Is it possible to display conditional HTML based on page name in wordpress?


I added a bit of custom HTML code to a website. Everything works just great. I am trying to display this HTML code based on the page name. I looked at some resources online and wrote out the code but it does not work. I have also checked online and I am only seeing ways to conditionally add CSS and JS. Is this something that is possible to do and how do I go about doing this?

My code
            global $wpdb;               
    $query = new WP_Query(array(
    'posts_per_page' => 12,
    'category_name' => 'featured-posts',
  $posts =  $query -> posts;
  if ( is_page('Featured Posts') ){
   foreach ($posts as $post) {  
      echo '
<div class="slider-container">
     <h4 class="slider-header">
       <span class="slider-header_text">Trending</span>

  <div class="slider">
   <div class="carousel-container">
     <div class="carousel-inner">
      <div class="track">  
        <div class="card-container">
        <a href="'.$post->guid.'" class="card">
            <div class="img">
             <img src="'.get_the_post_thumbnail_url( $post -> ID, 'thumbnail' ).'" alt="">
            <div class="info">
     <div class="nav">
      <button class="prev">
       <i class="fas fa-angle-left"></i>
      <button class="next">
       <i class="fas fa-angle-right"></i>
newbiefatcoder 4 months 0 Answers 25 views 0

Leave an answer