• Need php advice on using the escape attribute in the following link code for a news template: https://www.howlingwolfmedia.com/site3/news.
    The titles are not following h3 styling

    <?php
     $posts=get_posts('category=14&post_type=post&showposts=20');
         if ($posts) {
             foreach($posts as $post) {
             setup_postdata($post);
            ?>
        <h3 ><a href="<?php the_permalink() ?>"  ><?php the_title(); ?></a> </h3>
    
        <p style="margin-top:0; margin-bottom:12px">
        <?php
        if ($post->post_excerpt) {
          echo  $post->post_excerpt;
        }
      }
    }
    ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • Can you clarify what you mean by the “escape attribute”?

    Thread Starter lberelson

    (@lberelson)

    I think the problem with the title not displaying is b/c i do not know how to employ this within the code… https://codex.www.ads-software.com/Function_Reference/esc_attr. Or it may be another syntax problem. I don’t know how to incorporate proper html markup inside php code; if that is in fact the issue. It could be css… here’s the markup for the links on h tags.

    h1,h2,h3,h4,h5,h6 {
    	font-family: Verdana, Trebuchet, sans-serif;
    	margin: 3px 0 0 0;
    	padding: 3px 0 0 0;
    	}
    
    h1 {
    	font-size: 1.7em !important;
    	color: #1c94c4;
     	font-weight: bold;
    	}
    
    h1 a, h1 a:link, h1 a:visited, h1 a:hover, h1 a:active {
    	text-decoration: none;
    	}
    
    h2 {
    	font-size: 1.5em;
    	color: #dba303;  /*yelloworange*/
     	font-weight: bold;
    	}
    
    h2 a, h2 a:link, h2 a:visited, h2 a:hover, h2 a:active {
     	text-decoration: none;
    	}
    
    h3 {
    	font-size: 1.5em;
    	color: #90be4d;  /*green*/
     	font-weight: bold;
    	}
    
    h3 a, h3 a:link, h3 a:visited, h3 a:hover, h2 a:active {
     	text-decoration: none;
    	}
    
    h4 {
        font-size: 1.5em;
    	color: #db7d03;  /*orange*/
    	font-weight: bold;
    	}
    
    h4 a, h4 a:link, h4 a:visited, h4 a:hover, h4 a:active {
    	text-decoration: none;
    	}

    What exactly are you trying to insert into your Posts and/or Pages?

    Lisa

    (@berelsonhotmailcom)

    Just a standard news listing page of category id 14. i didn’t use custom post types.

    looks like you have fixed the issue – there seems just a space character missing;

    please post the current code if you like to have it corrected;

    also review https://codex.www.ads-software.com/Function_Reference/the_title_attribute

    Lisa

    (@berelsonhotmailcom)

    Not yet. It’s a styling issue; nothing to do with esc attr. I just replaced the link with a simple slug and it still doesn’t work. Additionally doesn’t work in body copy either when h tags are linked so it’s nothing to do with the php code etc.
    p.s. I also took out the query_post filter and replaced with WP_query as query_post was not recommended by codex.

    code using a link slug

    <?php
    // the query
    $newsquery = new WP_Query( 'category_name=news' ); ?>
    
    <?php if ( $newsquery->have_posts() ) : ?>
    
      <?php while ( $newsquery->have_posts() ) : $newsquery->the_post(); ?>
        <h2 class="news"><a href="#"><?php the_title(); ?></a></h2>
        <?php the_excerpt(); ?>
      <?php endwhile; ?>
    
      <?php wp_reset_postdata(); ?>
    
    <?php else:  ?>
      <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
    <?php endif; ?>

    I’ll close out ticket and futz with css more.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Esc attribute’ is closed to new replies.