Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #866756
    Amma1
    Participant

    Hi,

    I was wondering if it were possible to have the post categories showing above the post title (but still below the featured image) on single posts?

    I want the top of my posts to be like this:
    – Featured Image
    – Post Categories
    – Post Title
    – Post Date
    – Post Content

    I’ve managed to get the date to display with a shortcode but I’m not sure what to add to wp-single.php to get it to run the date after the title but before the content but am not sure how to get it to show the categories above the title. Perhaps there is a way for it to display the meta above the post title and then disable everything in the meta except the categories?

    I’m using a child theme with the integrity stack btw 🙂

    Thanks

    Rob

    #867282
    Christopher
    Moderator

    Thanks for writing in! To assist you with this issue, we’ll first need you to provide us with your URL. This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.

    #870383
    Amma1
    Participant
    This reply has been marked as private.
    #870722
    Rad
    Moderator

    Hi there,

    Hmm, that would be tricky since your post date is manually added to the content. Why not just enable post meta through customizer then customize its code?

    You can enable it at Admin > Appearance > Customizer > Blog > CONTENT > Post Meta, then we can just re-arrange the order of post meta through coding. Let me know.

    Thanks!

    #872016
    Amma1
    Participant

    Ah, ok yes I have turned this on now. Could you tell me how to rearrange the meta (I only want the categories)

    Thanks

    #872626
    Paul R
    Moderator

    Hi,

    To achieve that, you can add this in your child theme’s functions.php file.

    
    function x_integrity_entry_meta() {
    
        //
        // Author.
        //
    
        $author = sprintf( '<span><i class="x-icon-pencil" data-x-icon=""></i> %s</span>',
          get_the_author()
        );
    
        //
        // Date.
        //
    
        $date = sprintf( '<span><time class="entry-date" datetime="%1$s"><i class="x-icon-calendar" data-x-icon=""></i> %2$s</time></span>',
          esc_attr( get_the_date( 'c' ) ),
          esc_html( get_the_date() )
        );
    
        //
        // Categories.
        //
    
        if ( get_post_type() == 'x-portfolio' ) {
          if ( has_term( '', 'portfolio-category', NULL ) ) {
            $categories        = get_the_terms( get_the_ID(), 'portfolio-category' );
            $separator         = ', ';
            $categories_output = '';
            foreach ( $categories as $category ) {
              $categories_output .= '<a href="'
                                  . get_term_link( $category->slug, 'portfolio-category' )
                                  . '" title="'
                                  . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                                  . '"><i class="x-icon-bookmark" data-x-icon=""></i> '
                                  . $category->name
                                  . '</a>'
                                  . $separator;
            }
    
            $categories_list = sprintf( '<span>%s</span>',
              trim( $categories_output, $separator )
            );
          } else {
            $categories_list = '';
          }
        } else {
          $categories        = get_the_category();
          $separator         = ', ';
          $categories_output = '';
          foreach ( $categories as $category ) {
            $categories_output .= '<a href="'
                                . get_category_link( $category->term_id )
                                . '" title="'
                                . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                                . '"><i class="x-icon-bookmark" data-x-icon=""></i> '
                                . $category->name
                                . '</a>'
                                . $separator;
          }
    
          $categories_list = sprintf( '<span>%s</span>',
            trim( $categories_output, $separator )
          );
        }
    
        //
        // Comments link.
        //
    
        if ( comments_open() ) {
    
          $title  = apply_filters( 'x_entry_meta_comments_title', get_the_title() );
          $link   = apply_filters( 'x_entry_meta_comments_link', get_comments_link() );
          $number = apply_filters( 'x_entry_meta_comments_number', get_comments_number() );
    
          if ( $number == 0 ) {
            $text = __( 'Leave a Comment' , '__x__' );
          } else if ( $number == 1 ) {
            $text = $number . ' ' . __( 'Comment' , '__x__' );
          } else {
            $text = $number . ' ' . __( 'Comments' , '__x__' );
          }
    
          $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments"><i class="x-icon-comments" data-x-icon=""></i> %3$s</a></span>',
            esc_url( $link ),
            esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
            $text
          );
    
        } else {
    
          $comments = '';
    
        }
    
        //
        // Output.
        //
    
        if ( x_does_not_need_entry_meta() ) {
          return;
        } else {
          printf( '<p class="p-meta">%s</p>',     
            $categories_list       
          );
        }
    
      }
    

    Hope that helps.

    #875738
    Amma1
    Participant

    Hi,

    Thanks, thats only showing the categories now. The only thing now is that it is still displaying below the post title whereas I would like it to appear above the post title?

    Thanks

    #876151
    Rue Nel
    Moderator

    Hello There,

    To display the post meta or categories above your post titles, since you have your child theme active and ready, please follow the following steps below:
    1] Using Notepad or TextEdit or Sublime Text or any text editor, please create a new file in your local machine.
    2] Insert the following code into that new file

    <?php
    
    // =============================================================================
    // VIEWS/INTEGRITY/_CONTENT-POST-HEADER.PHP
    // -----------------------------------------------------------------------------
    // Standard <header> output for various posts.
    // =============================================================================
    
    ?>
    
    <header class="entry-header">
    
      <?php x_integrity_entry_meta(); ?>
      
      <?php if ( is_single() ) : ?>
      <h1 class="entry-title"><?php the_title(); ?></h1>
      <?php else : ?>
      <h2 class="entry-title">
        <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to: "%s"', '__x__' ), the_title_attribute( 'echo=0' ) ) ); ?>"><?php x_the_alternate_title(); ?></a>
      </h2>
      <?php endif; ?>
      
    </header>

    3] Save the file named as _content-post-header.php
    4] Upload this file to your server in the child theme’s folder
    wp-content/themes/x-child/framework/views/integrity/

    Please let us know if this works out for you.

    #877188
    Amma1
    Participant

    Ah! that’s great 🙂

    How can I remove the commas between the categories?

    Thanks

    Rob

    #877847
    Lely
    Moderator

    Hello Rob,

    Please update the code suggested above on reply #872626.
    Look for this line of code:
    $separator = ', ';
    Update to this:
    $separator = ' ';
    It is below this line:
    $categories = get_the_terms( get_the_ID(), 'portfolio-category' );

    Hope this helps.

    #878184
    Amma1
    Participant

    Great, thanks!

    #878651
    Prasant Rai
    Moderator

    You are most welcome.

  • <script> jQuery(function($){ $("#no-reply-866756 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>