Home › Forums › Pro Support › Use WP Show Posts to Replace Blog Archive Page
Tagged: Blog Archive
- This topic has 32 replies, 6 voices, and was last updated 2 years, 2 months ago by
elvin.
-
AuthorPosts
-
August 5, 2020 at 4:52 am #17954
Jon
ParticipantI’m loving learning this plugin! One thing I haven’t figured out yet is how I might be able to replace my standard blog archive page https://matchlessweb.com/blog with the WP Show Posts blog list I’ve created (currently demoed on my testing page: https://matchlessweb.com/search).
I know the list I created generates a shortcode as well as a function. I imagine I’ll have to do something with that function if I want to have my desired WPSP list drop into my blog archive template. I’m just not sure how to go about that. My search through this forum for “blog archive” related things didn’t seem to turn up anything that looked similar to what I’m looking to do. So I hope I’m not missing something obvious or asking a repeat question that’s already been answered elsewhere.
Any tips to get me going in the right direction are much appreciated.
August 5, 2020 at 1:03 pm #17965Tom
KeymasterHey Jon,
You’re right that you would need to place that function in your archive template, replacing the standard loop that exists there.
Would this be for a specific archive or all archives?
August 5, 2020 at 1:43 pm #17971Jon
ParticipantThanks for that Tom! Would you recommend me creating a child template for that archive template before trying to add the WPSP loop function?
I was primarily thinking of making this for my blog posts only. But I’d also be interested in setting this up for CPTs. I have a CPT for my portfolio items called “projects”. I created the CPT using Toolset Types, but I’m not using what would be the normal/default archive page: https://matchlessweb.com/project that would be created by Toolset if I enabled that archive page.
I much rather prefer the look of WPSP. So i created this page: https://matchlessweb.com/projects and just dropped the shortcode for my projects lists there. So that page isn’t necessarily acting like a true archive page I suppose. But it has given me the look I’m after.
Any of my projects have this kind of file path: https://matchlessweb.com/project/ms-mane-co/
But if you remove the end of that slug, and just visit https://matchlessweb.com/project ,that of course would not be the pseudo-archive page I’m currently using https://matchlessweb.com/projects.
So I know that doesn’t really work as a real archive setup. But would I be able to get WPSP acting as the loop for my archive for that CPT?
August 6, 2020 at 2:44 pm #18007Tom
KeymasterAs of right now, it’s quite difficult as WordPress never really intended on having static pages act as archives.
Basically, you would need to create a custom page template for the category/custom post type etc..
Then you would create a WPSP list, and replace the loop in that archive with the
wpsp_display()
function.This user wrote a pretty thorough how-to on how they achieved it: https://generatepress.com/forums/topic/create-custom-category-php-template-wp-show-posts-wpsp/
August 6, 2020 at 2:57 pm #18013Jon
ParticipantThat’s a big help Tom! Thanks for that link about the custom page template for category/CPT.
Regarding the standard blog archive, would you recommend me creating a child template for that archive template before replacing the standard loop with the WPSP loop function for the list I’ve created? Or should I just edit the default file in hopes I don’t break things. I can of course create a copy before I edit anything in case things were to go south.
August 7, 2020 at 12:51 pm #18038Tom
KeymasterDefinitely create child theme files for those edited files. If you edit the parent files, all of your changes will be lost when you update the theme.
August 7, 2020 at 2:56 pm #18042Jon
ParticipantI followed the tutorial you referenced, Tom.
I replaced the default loop of the parent archive template (archive.php) with my WPSP function and that code looks like this:
<?php /** * The template for displaying Archive pages. * * @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' ); <?php if ( function_exists( 'wpsp_display' ) ) wpsp_display( 1736 ); ?> /** * 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(); get_footer();
Now my question is: Do I need to name the file something different than “archive.php” if I want to put it in my child theme and have it replace the standard blog archive page template?
August 8, 2020 at 4:54 pm #18071Tom
KeymasterDo this instead:
if ( function_exists( 'wpsp_display' ) ) wpsp_display( 1736 );
If you name it
archive.php
, it will replace ALL archives throughout the site.This might help: https://developer.wordpress.org/themes/basics/template-hierarchy/
November 12, 2020 at 4:11 pm #22550Jim
ParticipantI followed this and put the code on a custom category.php in my child theme. I’m not using static pages–I’m just trying to customize my category archive pages. So when I add the code above it works, but all categories display the same content.
I figured maybe I need to use this function or something similar: https://docs.wpshowposts.com/article/use-static-pages-as-category-archives/
However, I get an error when I add that code. FYI: I’m running Yoast and have it set to remove the /category/ part from my category URLs, so not sure if that’s causing a problem.
Any advice?
November 13, 2020 at 10:02 am #22599Jim
ParticipantI think I resolved this. Let me know if it looks right.
Using the custom category template example above, I changed this line:
if ( function_exists( 'wpsp_display' ) ) wpsp_display( 1736 );
to this:
$cat = get_category( get_query_var( 'cat' ) ); $cat_slug = $cat->slug; if ( function_exists( 'wpsp_display' ) ) wpsp_display( 8033, 'tax_term="' . $cat_slug . '"' );
My post list ID is different, of course, but this seems to be working for me. Look okay?
November 16, 2020 at 3:17 pm #22752Tom
KeymasterLooks good to me! 🙂
March 11, 2021 at 2:55 pm #27926Kar Yung
ParticipantTom, in the latest versions of GP, I guess I’m replacing the entire generate_has_default_loop() from archive.php? Just making sure.
March 11, 2021 at 6:48 pm #27934elvin
ModeratorHi there,
Yes that’s pretty much what you have to replace for your template files.
But
generate_has_default_loop
is a filter as well.https://docs.generatepress.com/article/generate_has_default_loop/
You can change the loop with WPSP without even using a child theme with this PHP snippet:
https://gist.github.com/ejcabquina/1dbe569d75ea2f15a024ec5dbdba0362
Note: this is just a base condition. It’ll be signifcantly more complex if you want the WPSP list to display the category query.
You’ll have to add the topic starter’s condition for categories.
https://wpshowposts.com/support/topic/use-wp-show-posts-to-replace-blog-archive-page/#post-22599Example:
https://gist.github.com/ejcabquina/60f052a3667da05d479749cb3be3daad
March 12, 2021 at 10:34 am #27944Kar Yung
ParticipantWow, that IS an awesome alternative. I realize that my home page and my categories archive do differ a bit and I found that it’s because of this CSS.
.separate-containers .inside-article{
}
This is applied to the articles on the homepage but not to the category pages. What’s the best way to have them be the same? I actually think the category ones look better (without the spaces, makes the main column pop more).
March 14, 2021 at 7:06 pm #28024elvin
ModeratorIf you’re using GP Premium, you can use this filter for that:
https://docs.generatepress.com/article/option_generate_settings/add_filter( 'option_generate_settings','lh_single_posts_settings' ); function lh_single_posts_settings( $options ) { if ( is_category() ) { $options['content_layout_setting'] = 'one-container'; } return $options; }
-
AuthorPosts
- You must be logged in to reply to this topic.