Edit category post template

Hi,

How can I edit the template for the category posts?
https://www.dangerpress.com/t-shirts/

Best regards,

J

Hello Jhaysin,

Thanks for writing in!

Customizing category post template will require making changes in the theme files which regretfully falls outside the scope of support we can offer.

However you can get an idea by following this thread (https://theme.co/apex/forum/t/creating-default-post-templates-by-category/15909).

Also you can read about our planned layout builder here (https://theme.co/apex/forum/t/status-report-july-31-2018/39909) on our status report.

Thanks!

Thanks Prasant.

I found info info from previous answers about recreating the pro-child/archive.php and pro-child/category.php files, so I’m good there.

To be clear, it’s not actually the category page I want to edit, I can do that in Theme Options/Blog, but the post structure of each archive post listed on the page.

Just this part. Currently it’s just random meta data attached to the post in no logical order.

Is that archive post structure defined by Pro somewhere?
Can I hide it with CSS and replace with Cornerstone content?

J

Hello Jhaysin,

Thank you for the clarifications. The random meta data is actually the post meta. You can enable or disable it in X > Theme Options > Blog > Content > Post Meta.

Each stack has a unique design and structure in displaying the post meta. If you want to modify the post meta, you can simply add this code in your child theme’s functions.php file.

// Custom Entry Meta
// =============================================================================

if ( ! function_exists( 'x_renew_entry_meta' ) ) :
  function x_renew_entry_meta() {

    //
    // Author.
    //

    $author = sprintf( '<span>%s</span>',
      get_the_author()
    );


    //
    // Date.
    //

    $date = sprintf( '<span><time class="entry-date" datetime="%1$s">%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 ) )
                              . '"> '
                              . $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 ) )
                            . '">'
                            . $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() );


	  $text = ( 0 == $number ) ? __( 'Leave a Comment', '__x__' ) : sprintf( _n( '%s Comment', '%s Comments', $number, '__x__' ), $number );


	  $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%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">%1$s%2$s%3$s%4$s</p>',
        $author,
        $date,
        $categories_list,
        $comments
      );
    }

  }
endif;
// =============================================================================

Please do not forget to add your modifications in the code above or else nothing will change.

Thanks RueNel.

I already have this code in my pro-child/functions.php to control the post meta of my wp-single.php posts.

For instance

If I adjust what is in the functions.php, it will change the design of my main posts, which I don’t want to do.

I’m trying to get the archive/category post previews like this
https://www.dangerpress.com/t-shirts/

To look like this
https://www.dangerpress.com/posts/

Google is indexing these archive/category post previews and creating links with the authors name listed twice at the beginning instead of the content I want in SEO.

Is there a name for these auto-generated archive/category post previews and is there a way to control their layout independent of editing my wp-single.php posts?

J

Hello Jhaysin,

The Posts page was created with WPBakery and it is a normal page. The T Shirts is a category archive index. The Archive/Category index pages are using the index.php and it is independent from your wp-single.php. If you want to modify, you will have to duplicate index.php and named it as your category.php along with your modifications in it.

These links might help you:

Thanks RuNel,

It seems like an oversight by WPBakery that you can’t edit Category/Archive Pages using their editor.

This plugin came out a couple of months ago that looks like it may allow for that functionality.

J

Hey Jhaysin,

The given plugin (Customize Post Categories For WPBakery Page Builder) is not connected to WPBakery. The plugin (Customize Post Categories For WPBakery Page Builder) is a WPBakery extension which enables you to edit the archive pages as they claim to be. This, however, does not mean that any support should be directed to WPBakery plugin. If you already have installed and plugin and has encountered some issues or interested in trying out this plugin (Customize Post Categories For WPBakery Page Builder), it is best that you contact the creators of the plugin, the Mysterious_Team.

Thank you for your understanding.

Thanks RueNel.

I did everything you suggested and was able to get a solution using the WPBakery Post Grid element, filtering by category.

J

Glad that you managed to find a solution :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.