WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Sticky Post Title Set as <h1> (9 posts)

  1. cableghost
    Member
    Posted 4 years ago #

    What code, and where would I place it, to make only sticky post titles presented as <h1>?

  2. Shane G
    Member
    Posted 4 years ago #

    Hi,

    You can use the custom stylesheet for your sticky post. Refer this article for more details

    http://codex.wordpress.org/Theme_Development#Theme_Style_Sheet

    Thanks,

    Shane G.

  3. esmi
    Forum Moderator
    Posted 4 years ago #

    Something like:

    <?php if( is_sticky() ) ?><h1>
    <?php else ?><h2>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    <?php if( is_sticky() ) ?></h1>
    <?php else ?></h2>

    should work in index.php

  4. cableghost
    Member
    Posted 4 years ago #

    Thanks Shane G

    The code you provided esmi does not function in this case. I am using a theme that does not presently recognize sticky posts. I had to add the following code in order to make sticky posts effective. Is there a way to edit this code to accomplish my inquiry?

    <?php query_posts(array('post__in'=>get_option('sticky_posts'))); ?>

    -Scott

  5. esmi
    Forum Moderator
    Posted 4 years ago #

    I am using a theme that does not presently recognize sticky posts

    The conditional should still work - even if your current theme doesn't normally highlight sticky posts in any way. It's a WP database flag rather than a theme one.

  6. cableghost
    Member
    Posted 4 years ago #

    Unfortunately, I placed the code in index.php and I received a php error. Should it be placed in a specific position w/in index.php?

    "Parse error: syntax error, unexpected T_ELSE in..."

  7. esmi
    Forum Moderator
    Posted 4 years ago #

    Ah! Now that's different. That's just sloppy coding/typing on my part. :-)

    Try:

    <?php if( is_sticky() ) :?><h1>
    <?php else :?><h2>
    <?php endif;?>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
    <?php if( is_sticky() ) :?></h1>
    <?php else :?></h2>
    <?php endif;?>
  8. cableghost
    Member
    Posted 4 years ago #

    Okay, no errors, but now it just displays 2 titles, both as <h2> :-)

    Here's my post title code in common.php that is setting post titles as <h2>:

    <h2 class="h2-simulate-h1-size"><a href="<?php the_permalink() ?>" rel="bookmark">
    			<?php the_title(); 													// Because single post or pages are more important for indexing, multiple post pages just have a h2 title for each item
    			?>
    			</a></h2>

    Here's the code to only display sticky posts on home page in my home/index.php:
    <?php query_posts(array('post__in'=>get_option('sticky_posts'))); ?>

    Wondering if maybe there's a means to combine your code with my existing post tile code above.

    -Scott

  9. cableghost
    Member
    Posted 4 years ago #

    Since this is not working out to well, I'm going to change approaches and have started a new post:

    http://wordpress.org/support/topic/328607?replies=1#post-1271093

Topic Closed

This topic has been closed to new replies.

About this Topic