WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Modify h1/h2 rules on my theme (6 posts)

  1. silis25
    Member
    Posted 1 year ago #

    Hi,

    I would like to modify h1/h2 rules on my theme as follows:

    1. On Front page: Site Title=h1 and Article titles=h2
    2. On Single Post Pages: Site title=h2 and Article titles=h1

    I would like to know what php code to add to make this happen.

    Thanks,

    Kfir Silis
    http://www.letthemstare.com

    single.php

    <?php get_header( header.php ); ?>
    
    <div id="content">
    <div class="inside">
    
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    <div class="post">
    <p class="date"><?php the_date(); ?></p>
    <h2 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <div class="largepic"><center>
    <?php
        $attachments = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order'));
        if ( ! is_array($attachments) ) continue;
        $count = count($attachments);
        $first_attachment = array_shift($attachments);
        $size = 'full';
        ?>
        <?php echo wp_get_attachment_image($first_attachment->ID, $size); ?>
    </center>
    </div>
    
    <div id="post-content">
    <div class="content-text">
      <p><?php
      ob_start();
      the_content('Read the full post',true);
      $postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
      ob_end_clean();
      echo $postOutput;
      ?></p>
    </div>
    
    <div class="content-img">
      <?php
      preg_match_all("/(<img [^>]*>)/",get_the_content(),$matches,PREG_PATTERN_ORDER);
      for( $i=0; isset($matches[1]) && $i < count($matches[1]); $i++ ) {
        echo $beforeEachImage . $matches[1][$i] . $afterEachImage;}?>
    </div>
    </div>
    
    <div class="clear"></div>
    
    <ul id="share">
    <div class="fb-like" data-href="<?php the_permalink(); ?>" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false" data-font="trebuchet ms"></div>
    </ul>
    <div class="clear"></div>
    
    <div style="margin-bottom: -90px;" class="fb-comments" data-href="<?php the_permalink(); ?>" data-num-posts="5" data-width="940"></div>
    
    </div>
    <?php endwhile; ?>
    
    </div>
    </div>
    
    <?php get_footer( footer.php ); ?>
  2. Max
    Member
    Posted 1 year ago #

    check out the conditional tags, specifically is_home() and is_single().

    You can achieve that with those conditionals and a couple of if statements.

  3. silis25
    Member
    Posted 1 year ago #

    I will look into it.
    Do you have any example of such a use?

  4. silis25
    Member
    Posted 1 year ago #

    When I think about it, I would prefer all of my titles to be h1 tagged (homepage or single) so if I change that line from:

    <h2 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>

    to

    <h1 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>

    That will do the trick but the style of the titles is much bigger and different. So I've added the following on style.css:

    #content h1 a {
    	color: #d33300;
    	font-weight: normal;
    }
    #content h1 a:hover {
    	color: #000;
    }
    .title {
    font-size: 1.5em;
    font-weight: bold;
    font-family: Georgia;
    }

    How can I imitate exactly h2 style into class "title"?

  5. silis25
    Member
    Posted 1 year ago #

    OK now it's ok.
    Thank you :)

  6. silis25
    Member
    Posted 1 year ago #

    Forgot to mark the topic as resolved.
    Resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags