• Hi,

    I added the date of each post under the Post titles on my homepage here:

    internalcompass.us/castle

    Awkwardly, random dates are now also displaying in the Nav…. ?Can someone please peruse this code, and tell me if you know how I can just make the dates show only on the posts?

    Here is the code I added to functions.php to make the dates display:

    <?php
    function add_dates_to_title_wpse106605($title, $id) {
        if (is_home()){
            $time = get_the_time( $d = 'l, F j, Y', $post = $id );
            return $title . '<small class="time">' . $time . '</small>';
        } else {
            return $title;
        }
    }
    
    add_filter('the_title', 'add_dates_to_title_wpse106605', 10, 2);
    ?>

    Here is the code I have in my index.php child file:

    [Please use a pastebin for posting that much code]

    thx

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter dequecolour

    (@dequecolour)

    omg sorry i thought i entered the code between backticks ugh! sorry!

    Thread Starter dequecolour

    (@dequecolour)

    this is the code i tried to paste above. also if y’all need to delete this post, and i can create a new one, that is fine. i’m just puzzled.

    i added this filter in functions.php which worked except it put the dates in the Nav which i do not want!

    maybe i need other code after the if is home in line 3. but bc of the code i have in my index.html i can’t just use if is the loop. that doesn’t work at all.

    <?php
    function add_dates_to_title_wpse106605($title, $id) {
        if (is_home()){
            $time = get_the_time( $d = 'l, F j, Y', $post = $id );
            return $title . '<br><small class="time">' . $time . '</small>';
        } else {
            return $title;
        }
    }
    
    add_filter('the_title', 'add_dates_to_title_wpse106605', 10, 2);
    ?>

    here is my index.php

    <?php
    /**
     * The main template file.
     *
     * This is the most generic template file in a WordPress theme
     * and one of the two required files for a theme (the other being style.css).
     * It is used to display a page when nothing more specific matches a query.
     * For example, it puts together the home page when no home.php file exists.
     *
     * Learn more: https://codex.www.ads-software.com/Template_Hierarchy
     *
     * @package WordPress
     * @subpackage Twenty_Twelve
     * @since Twenty Twelve 1.0
     */
    
    get_header(); ?>
    	<div id="primary" class="site-content">
    		<div id="content" role="main">
    
            <div style="margin-bottom: 20px;">
    
            </div>
            <a href="internalcompass.us/castle" target="_blank">
    
    <?php easyrotator_display_rotator('erc_79_1374391970'); ?>
    
    </div>
            <a href="internalcompass.us/castle" target="_blank">
    <img src="https://internalcompass.us/castle/wp-content/uploads/2013/07/recent-posts1.jpg" border="0" style="border:none;max-width:100%;" alt="recent posts favorite posts" />
    </a>
    <div id="right-column">
    <?php $my_query = new WP_Query('category_name=favorites');
      while ($my_query->have_posts()) : $my_query->the_post();
      $do_not_duplicate[] = $post->ID ?>
      <?php get_template_part( 'content', get_post_format() ); ?>
      <?php endwhile; ?>
    </div>
    <div id="left-column">
    <?php $my_query = new WP_Query('category_name=Recents');
      while ($my_query->have_posts()) : $my_query->the_post();
      $do_not_duplicate[] = $post->ID ?>
      <?php get_template_part( 'content', get_post_format() ); ?>
      <?php endwhile; ?>
    </div>
    
    			<?php twentytwelve_content_nav( 'nav-below' ); ?>
    		</div><!-- #content -->
    	</div><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Dates on Posts on Homepage — also displaying in Nav..’ is closed to new replies.