We're merging with GenerateBlocks! Learn more here.

[Support request] Use WP Show Posts to Replace Blog Archive Page

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Use WP Show Posts to Replace Blog Archive Page

Tagged: 

Viewing 15 posts - 1 through 15 (of 33 total)
  • Author
    Posts
  • #17954
    Jon
    Participant

    I’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.

    #17965
    Tom
    Keymaster

    Hey 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?

    #17971
    Jon
    Participant

    Thanks 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?

    #18007
    Tom
    Keymaster

    As 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/

    #18013
    Jon
    Participant

    That’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.

    #18038
    Tom
    Keymaster

    Definitely 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.

    #18042
    Jon
    Participant

    I 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?

    #18071
    Tom
    Keymaster

    Do 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/

    #22550
    Jim
    Participant

    I 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?

    #22599
    Jim
    Participant

    I 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?

    #22752
    Tom
    Keymaster

    Looks good to me! 🙂

    #27926
    Kar Yung
    Participant

    Tom, in the latest versions of GP, I guess I’m replacing the entire generate_has_default_loop() from archive.php? Just making sure.

    #27934
    elvin
    Moderator

    Hi 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-22599

    Example:

    https://gist.github.com/ejcabquina/60f052a3667da05d479749cb3be3daad

    #27944
    Kar Yung
    Participant

    Wow, 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).

    https://magic.facetofacegames.com

    #28024
    elvin
    Moderator

    If 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;
    }
Viewing 15 posts - 1 through 15 (of 33 total)
  • You must be logged in to reply to this topic.