[Resolved] Conditional 'generate_archive_title'

Home Forums Support [Resolved] Conditional 'generate_archive_title'

Home Forums Support Conditional 'generate_archive_title'

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #271991
    Lyle

    Not really a support question, just a way to enhance GP and WPSP πŸ™‚

    The set up:
    – use a page builder to spiff up a page that will be the “Blog” page, that is, a listing of the blogs, using WPSP shortcode to display them.
    – this works fine and dandy πŸ™‚
    – however, when a user selects one of those posts to read and then clicks the “Category” link in the single post meta, they are taken to the default archive.php page, which of course does not look as “spiffy” πŸ™‚

    The “Fix” (well, for a single category anyway, and the reason for this query)
    – copy the GP archive.php file to the GP child theme and then edit as such:
    – remove this:

    <?php /* Start the Loop */ ?>
    			<?php while ( have_posts() ) : the_post(); ?>
    
    				<?php
    					/* Include the Post-Format-specific template for the content.
    					 * If you want to override this in a child theme, then include a file
    					 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
    					 */
    					get_template_part( 'content', get_post_format() );
    				?>
    
    			<?php endwhile; ?>

    … and replace it with this:

    <?php echo do_shortcode( '[wp_show_posts id=60]' ); ?>

    Works great with a single category. But when is more than one, it would be nice to have a “conditional” in there, such as this pseudo code:

    if generate_archive_title = category-one, then do this shortcode
    else
    if generate_archive_title = category-two, then do that shortcode
    … etc.

    I only know enough PHP to get me into trouble so if you have a minute to suggest something, it will be greatly appreciated πŸ™‚

    http://snifflevalve.com
    Tutorials and tips for GeneratePress, WP Show Posts, WordPress and Elementor

    GeneratePress 1.3.43
    GP Premium 1.2.94
    #272005
    Tom
    Lead Developer
    Lead Developer

    That would definitely work! You can actually append the category slug to the file so that file will only apply to that specific category: https://developer.wordpress.org/themes/basics/template-hierarchy/#category

    Also, no need to use the shortcode in the file, you can use the function provided while adding your list πŸ™‚

    #272007
    Lyle

    Thats perfect Tom! πŸ™‚ THANKS!

    And for goodness sakes, I forgot all about the function being there in the WPSP list … I only “see” the shortcode πŸ™‚

    I detect a tutorial video coming soon πŸ™‚

    Cheers!
    Lyle

    http://snifflevalve.com
    Tutorials and tips for GeneratePress, WP Show Posts, WordPress and Elementor

    #272046
    Tom
    Lead Developer
    Lead Developer
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.