Archived topic
Generatepress custom page best practise
5 replies · Started by Ginaphi on December 10, 2020
Hi, i try to make a custom page manually within GP theme. as much as possible, i want to avoid conflict to gp theme and still follow gp theme structuring. im using child theme at the moment to avoid messing with gp original structure.
what i have :
- Custom Post named "Tips" created using "Custom Post Type UI" plugin
- Several Custom fields assigned to "Tips" using "Advanced Custom Fields" plugin
my objective :
- create a custom page that will display published "Tips"
- create a custom single page to display clicked "Tips"
i stumble upon https://generatepress.com/forums/topic/building-custom-template-for-cpt-single-archive-php-pages-with-gp/ but im quiet confuse with it.
this is what i've tried :
- copy page.php to child theme, rename to page-tips.php
- copy content.php to child theme, rename to content-tips.php
- page-tips.php use get_template_part('content','tips');
- content-tips.php -> this is where im lost, i dont get where gp display the html output for the loop, i wish to change the loop to access Custom post "Tips" and its custom fields
are above approach is correct? and also how about the single.
Thank you
okay, i found way now to change the loop :
- in page-tips.php
<main id="main" <?php generate_do_element_classes( 'main' ); ?>>
<?php
/**
* generate_before_main_content hook.
*
* @since 0.1
*/
do_action( 'generate_before_main_content' );
$wpquery = new WP_Query(array(
'posts_per_page' => -1,
'post_type' => 'betting-tips',
'post_status' => 'publish',
'orderby' => 'publish_date',
'order' => 'DESC',
));
$img_html = '';
while ($wpquery->have_posts()) {
$wpquery->the_post();
get_template_part('content','betting-tips');
}
wp_reset_postdata();
/**
* generate_after_main_content hook.
*
* @since 0.1
*/
do_action( 'generate_after_main_content' );
?>
</main>
but i still confuse to how i can modify the output in content-tips.php
Nevermind, i guess i have to learn the theme_function of gp for this.
but more documentation regarding this would be helpful.
Hi there,
content-x.php is a file that gets included into the page.php template - it's there only for organization purposes, as it allows users to overwrite the loop only without having to overwrite the entire template.
In your case, just remove the get_template_part() and add your custom loop in its place :)
On a related note, how would I create an alternate 'Blog/Posts' page that displays the default blog loop, but 'orderby=modified'. (maybe this should be a separate post)
This is likely better suited as a new post.
Thanks!