Forum Replies Created
-
AuthorPosts
-
Dee
ParticipantSo this site is live now, so perhaps some links will help. I disabled my redirect, so you can see both pages.
I have 2 pages and both are identical /posts and /blog with content
[wp_show_posts name=”Simple”]I currently have /posts/ set as my static blog page, and am redirecting to blog to get the format I desire with the above shortcode.
If a switch the static page to point to /blog, then the default format (from where?) is shown, and not the wpshowposts shortcode version.The above coding works on the category and CPT archives, just not the main archive.
https://www.deezunkerphotography.com/blog/
https://www.deezunkerphotography.com/posts/Dee
ParticipantI thought this was working correctly as I had my blog redirected to a page, but for my generic “blog” archive, I am not getting the correct WPshowposts. I belive it is the “else” below, but I am not sure how to fix this.
Here is what I have in the content section of the archive.php file”if ( have_posts() ) : /** * generate_archive_title hook. * * @since 0.1 * * @hooked generate_archive_title - 10 */ do_action( 'generate_archive_title' ); $cat = get_queried_object(); $cat_slug = $cat->slug; $cat_tax = $cat->taxonomy; if ($cat_tax=='category'): $list = get_page_by_title( 'Simple', 'OBJECT', 'wp_show_posts' ); elseif ($cat_tax=='event_category'): $list = get_page_by_title( 'Simple-Event', 'OBJECT', 'wp_show_posts' ); elseif ($cat_tax=='source'): $list = get_page_by_title( 'Simple-Client', 'OBJECT', 'wp_show_posts' ); endif; wpsp_display( $list->ID, 'tax_term="' . $cat_slug . '"' ); generate_content_nav( 'nav-below' ); else : get_template_part( 'no-results', 'archive' ); endif;
I am getting the generic post format instead of the wpsp_display format.
I have a page named “Blog”, and my Homepage settings are set to “Posts”.
Blog displays like I want, but when I switch my home page settings to “Blog” instead of “Posts” it reverts to the generic layout.
I have the archive.php saved in the GP-child theme.Dee
ParticipantFor those looking for a solution to use WPShowposts as the display of the archive pages, including with custom post types, here is what I did:
I have 2 custom post types, each with their own custom taxonomies which I created in PODS. I set the archive to true for each.
CPT ‘event’ custom taxonomy ‘event_category’
CPT ‘client’ custom taxonomy ‘source’1. Create a WP Show Posts list for each post type:
Post type: post Taxonomy: category
Post type: event Taxonomy: event_category
Post type: client Taxonomy: source2. Copy the archive.php file to the generatepress-child folder
3. Replace the coding between do_action( ‘generate_archive_title’ ); and generate_content_nav( ‘nav-below’ ); with the following
$cat = get_queried_object(); $cat_slug = $cat->slug; $cat_tax = $cat->taxonomy; if ($cat_tax=='category'): $list = get_page_by_title( 'Simple', 'OBJECT', 'wp_show_posts' ); elseif ($cat_tax=='event_category'): $list = get_page_by_title( 'Simple-Event', 'OBJECT', 'wp_show_posts' ); elseif ($cat_tax=='source'): $list = get_page_by_title( 'Simple-Client', 'OBJECT', 'wp_show_posts' ); endif; wpsp_display( $list->ID, 'tax_term="' . $cat_slug . '"' );
Issues resolved:
1. I originally used is_post_type_archive() for testing if an archive of a custom post type, but it only evaluates as true if the archive is of the custom post type, and not for the associated taxonomies2. get_category() returns an object, so you can get the slug value with the associated object or post, but for custom post types you use get_term() or get_the_terms() which returns an array, so you cannot get the slug value. I changed the code to get_queried_object() and it works for both custom post types and regular posts.
3. You need a different WP Show Post list for each different post type, which I missed for a while, even though it is obvious.
To minimize the coding further, you could remove the $list=get_page_by_title…. And just use the WPSP ID for each list, but I like being able to see which list is being used.
There is still a display issue with WPSP in archives with repeating post thumbnails which I will cover in another post.
Dee
ParticipantI used a archive.php in my child theme, and replaced everything from while and endwhile with this:
$cat = get_category( get_query_var( 'cat' ) ); $cat_slug = $cat->slug; $list = get_page_by_title( 'Simple', 'OBJECT', 'wp_show_posts' ); wpsp_display( $list->ID, 'tax_term="' . $cat_slug . '"' );
‘Simple’ is the name of your list from WP Show Posts
-
AuthorPosts