• Resolved globetrotterdk

    (@globetrotterdk)


    Can anyone help me remove the “entry was posted in” and “date” info from only one sticky post, without impacting anything else?

    I am developing a child theme based on twenty twelve, for a local human rights organization. I am using a sticky post on the blogroll, that tells about the organization, while the normal activity posts will scroll bellow it.

    I am testing a similar setup on another domain here.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Ayman

    (@aymanalzarrad)

    Copy the content.php file into your child theme so you can modify it from there.
    Than you have to target the meta function twentytwelve_entry_meta(); that is located in content.php file that you just copied in your child theme to check the post ID before rendering the meta.

    You can do something like this:

    <?php /* Get the post ID and store it into $postid */ ?>
         <?php $postid = get_the_ID(); ?>
         <?php
              /*
               * Check if $postid is different from the target post ID
               * and if is different than show the post meta.
               * Note: You have to replace '1' with the post ID you are
               * targeting
               */
         ?>
         <?php if($postid != '1') : ?>
               <?php twentytwelve_entry_meta(); ?>
         <?php endif; ?>

    Note: You can even define twentytwelve_entry_meta(); in your child theme functions.php file to override the parent one. Where you an even add the check for the post you are targeting there.

    Thread Starter globetrotterdk

    (@globetrotterdk)

    Thanks for the quick reply. I am very new to php. I think I understand:

    <?php if($postid != '1') : ?>
               <?php twentytwelve_entry_meta(); ?>
         <?php endif; ?>

    However, I don’t understand how:

    <?php $postid = get_the_ID(); ?>

    will give me the ID number of the sticky post. It doesn’t appear to target any specific post type or single post to get the specific ID that I need.

    Lastly, I understand that unlike CSS, entire PHP files need to be copied to the child theme. That of course means that there is a lot of code already in PHP files. How do you determine where to place new code among already existing code in a PHP file?

    Ayman

    (@aymanalzarrad)

    <?php $postid = get_the_ID(); ?>

    Will only return the ID of a post in the loop. it returns (int) and than save that ID into a variable that we can use later on for the check against all the posts IDs in the loop.

    So in the above code first we are asking the loop to retrieve the of every post that will be displayed and than we are making the check to see if the returned ID is not the one we are targeting. And if the ID is not the one we are targeting than the meta will display as normal.

    You will have just to copy content.php file into your child theme and than search for this function:

    <?php twentytwelve_entry_meta(); ?>

    and than replace it with the one I gave above.

    Thread Starter globetrotterdk

    (@globetrotterdk)

    That worked, thanks ??

    I’d prefer rather than formatting for a specific post ID, that I can just format all sticky posts the same way. I don’t understand why “sticky” isn’t one of the body classes, then I could just hide the entry meta tags for all sticky posts.

    Rather than messing with the body_class function, I could use is_sticky() to add a class to some other tag, but now that I’ve cracked open the content.php file, I’m going to try this variation on Aymann’s code:

    <?php if (!is_sticky()) {twentytwelve_entry_meta();} ?>

    If I needed to wrap additional html around the meta output, I’d write it like this:

    <?php if (!is_sticky()) : ?>
               <!-- html goes here -->
               <?php twentytwelve_entry_meta(); ?>
               <!-- html goes here -->
    <?php endif; ?>

    Hope someone finds this helpful.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Twenty twelve child theme sticky post – removing "entry was posted"’ is closed to new replies.