- This topic has 5 replies, 3 voices, and was last updated 3 years, 3 months ago by Tom.
-
AuthorPosts
-
December 10, 2020 at 6:06 am #1574284fredyciang
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 fieldsare above approach is correct? and also how about the single.
Thank youDecember 10, 2020 at 7:14 am #1574495fredyciangokay, 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
December 10, 2020 at 7:33 am #1574521fredyciangNevermind, i guess i have to learn the theme_function of gp for this.
but more documentation regarding this would be helpful.December 10, 2020 at 11:19 am #1574754TomLead DeveloperLead DeveloperHi there,
content-x.php
is a file that gets included into thepage.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 🙂December 30, 2020 at 9:09 pm #1600302DwayneOn 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)
December 31, 2020 at 12:37 pm #1601047TomLead DeveloperLead DeveloperThis is likely better suited as a new post.
Thanks!
-
AuthorPosts
- You must be logged in to reply to this topic.