Site logo

Archived topic

Unable to change template file and disable the post excerpt

5 replies · Started by Vlad on August 26, 2022

Viewing posts 1–6 of 6

Hi there,
I'm using GP pro latest version with a simple GP child theme (some custom CSS styles and a modified query - no "phisical" HTML changes). I am trying to change the website so that, on the main posts lists (index.php and archive.php) the post category gets to be displayed on the same line with the post date, right beneath the post title. What php file should I edit in order to achieve this? I can't find the template in the theme's files.

Also, even if I deactivate the post excerpt in the WP builder (by setting the number of words to 0), the excerpt still gets displayed. I've managed to kill it with some CSS (display: none), however I would like to deactivate it via the website builder. Is this possible?

Thanks!
Vlad

Hi David,
Thank you for your suggestion - it worked, I managed to set up a content template (I'm sorry, I thought GP was too complex for me, however it turns out I am too lazy for it).

However, I can't get the index.php to offset the first 8 posts (these are being displayed using different templates). Could you help me with that? This is the code I have in 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.
 * E.g., it puts together the home page when no home.php file exists.
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package GeneratePress
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

get_header(); ?>

	<div <?php generate_do_attr( 'content' ); ?>>
		<main <?php generate_do_attr( 'main' ); ?>>
			<?php
			/**
			 * generate_before_main_content hook.
			 *
			 * @since 0.1
			 */
			do_action( 'generate_before_main_content' );

			
			//OFFSET X Posts w. pagination
			// via@ https://stackoverflow.com/questions/49227520/how-can-i-paginate-wp-query-results-when-theres-an-offset/49228080
			
			$current_page = get_query_var('paged');
			$current_page = max( 1, $current_page );
			$per_page = 30;
			$offset_start = 8;
			$offset = ( $current_page - 1 ) * $per_page + $offset_start;

			$post_list = new WP_Query(array(
				'posts_per_page' => $per_page,
				'paged'          => $current_page,
				'offset'         => $offset, // Starts with the second most recent post.
				'orderby'        => 'date',  // Makes sure the posts are sorted by date.
				'order'          => 'DESC',  // And that the most recent ones come first.
			));

			// Manually count the number of pages, because we used a custom OFFSET (i.e.
			// other than 0), so we can't simply use $post_list->max_num_pages or even
			// $post_list->found_posts without extra work/calculation.
			
			$total_rows = max( 0, $post_list->found_posts - $offset_start );
			$total_pages = ceil( $total_rows / $per_page );
			
			if ( generate_has_default_loop() ) {
				if ( $post_list->have_posts() ) :

					/**
					 * generate_before_loop hook.
					 *
					 * @since 3.1.0
					 */
					do_action( 'generate_before_loop', 'index' );

					while ( $post_list->have_posts() ) :

						$post_list->the_post();

						generate_do_template_part( 'index' );

					endwhile;

					/**
					 * generate_after_loop hook.
					 *
					 * @since 2.3
					 */
					do_action( 'generate_after_loop', 'index' );

				else :

					generate_do_template_part( 'none' );

				endif;
				wp_reset_postdata();
			}

			/**
			 * generate_after_main_content hook.
			 *
			 * @since 0.1
			 */
			do_action( 'generate_after_main_content' );
			?>
		</main>
	</div>

	<?php
	/**
	 * generate_after_primary_content_area hook.
	 *
	 * @since 2.0
	 */
	do_action( 'generate_after_primary_content_area' );

	generate_construct_sidebars();

	get_footer();

can i see the site, so i can get a better understanding of what should be happening ?

Hello David,
Thank you for your support, in the end I managed to get it to work.
All the best,
Vlad

Glad to hear that!

This archived topic is closed to new replies.