Site logo

Archived topic

Generatepress columns on custom query

21 replies · Started by Eroan on September 20, 2020

Viewing posts 16–22 of 22

Hard to tell without seeing the page. Does each featured image on the page have a featured-image page-header-image class?

Yes, that's it.

I cannot succeed in making posts render as in categories whatever I try.

Perhaps we need to take a step back - can you explain the desired end result? I assume you're trying to build a home page that has a mix of static content and posts? What about you doing with categories, exactly?

The idea is to display a page using front-page.php template.

In the first part, I display the page text in the classic way.

Then, under it I display the last posts links with the GeneratePress template in columns (same as categories, taxonomies...).

Not more than that. But so hard to achieve ^^

Displaying static content and post loops together on one page in WordPress is definitely difficult.

How much static content are you wanting to add above the posts? How are you building that content? Trying to think if there's a better way to do this.

I have one line of text.

The whole front-page.php template looks like this :

<?php
/**
 * The template for displaying all pages.
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package GeneratePress
 */

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

get_header(); ?>

	<div id="primary" <?php generate_do_element_classes( 'content' ); ?>>
		<main id="main" <?php generate_do_element_classes( 'main' ); ?>>
			<?php
			/**
			 * generate_before_main_content hook.
			 *
			 * @since 0.1
			 */
			do_action( 'generate_before_main_content' );

			while ( have_posts() ) : the_post();

				echo '<header class="page-header"><h1>Bienvenue sur '.get_bloginfo('name').'</h1>';

				the_content();

				echo '</header>';

			endwhile;

				?>

				<div class="page-header"><h2 class="actus">News</h2></div>

				<?php

				// The Query
    $query_options = array(
                    'post_type' => 'post',
                    'post_status' => 'publish',
                    'posts_per_page' => 6,
                    'order' => 'DESC',
                    'orderby' => 'date'
                    );

    $the_query = new WP_Query( $query_options );

    // The Loop
    if ( $the_query->have_posts() ) :

				while ( $the_query->have_posts() ) :

					$the_query -> the_post();

					get_template_part('content');

				endwhile; ?>

<?php endif; ?>

<?php

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

		</main><!-- #main -->
	</div><!-- #primary -->

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

	generate_construct_sidebars(); ?>

<?php get_footer();

I tried wp_reset_postdata() and wp_reset_query() after main content loop but it didn't help.

In that case, what about using the standard blog template as your front page, and then hooking a Block Element with your text onto the front page using Block Elements?: https://docs.generatepress.com/article/block-element-overview/

This way you're using the core GP blog template without forcing it to do something it wasn't built to do, and you can add whatever text you want up above the posts.

Let me know :)

This archived topic is closed to new replies.