Community Forums › Forums › Archived Forums › General Discussion › Display Posts from an Intersection of Categories
Tagged: 2 categories, featured posts
- This topic has 10 replies, 3 voices, and was last updated 7 years, 7 months ago by archana9.
-
AuthorPosts
-
February 22, 2017 at 3:30 pm #201787Alec BurnsMember
Hello! I need to display posts that are in both a category a and category b. (The actual usage case is more complex than this, so simply making a category that contains both categories doesn't work.) I know I need to modify the Featured Posts widget somehow but am not sure where to start, as PHP is not my strong suit. Any help in modifying Featured Posts, or advice on other widgets that could do the job, would be much appreciated.
Thank you!
Alec BurnsFebruary 22, 2017 at 3:55 pm #201788Brad DaltonParticipantDo you have to use the featured posts widget or can you use a custom loop?
February 22, 2017 at 3:57 pm #201789Alec BurnsMemberI believe a custom loop would work too, assuming it can accomplish the same task, but since I'm new to php/WordPress programming I figured modifying existing code would be more doable.
February 22, 2017 at 4:06 pm #201790Brad DaltonParticipantYou can modify the WP_Query args in the featured posts widget however you'll loose the changes when Genesis is updated unless you copy over the widget to your child theme.
Another option is to use genesis_custom_loop
Either way, you'll need to use 1 of these options for your $query args:
$query = new WP_Query( array( 'cat' => '1,2' ) ); $query = new WP_Query( array( 'category_name' => 'staff,news' ) );
February 23, 2017 at 12:39 am #201805Alec BurnsMemberThank you, that bit of code is quite helpful. Do you know anything that would make copying the featured posts widget to my child theme specifically difficult? I've copied the class Genesis_Featured_Post and have added it as-is to the end of my functions.php, renamed it Genesis_Featured_Post_Child and then have attempted to register it with
add_action( 'widgets_init', function() { register_widget( 'Genesis_Featured_Post_Child' ); } );
but the widget doesn't show up in that area of my admin panel. I copied over the foo example from the wordpress wiki, and that works fine, so I know it's not an issue with my child theme but with (I assume) the Featured Posts widget.Thanks again,
AlecFebruary 23, 2017 at 9:18 am #201817Alec BurnsMemberStrike that ^
(sorry, not sure how to delete posts.) Turned out I just forgot to update the constructed name.
February 23, 2017 at 12:16 pm #201829Brad DaltonParticipantBetween lines 69 and 75 in featured-post-widget.php you'll find the following code:
$control_ops = array( 'id_base' => 'featured-post', 'width' => 505, 'height' => 350, ); parent::__construct( 'featured-post', __( 'Genesis - Featured Posts', 'genesis' ), $widget_ops, $control_ops );
Change both instances of the i.d base from featured-post to something unique
February 25, 2017 at 11:33 pm #201973Alec BurnsMemberThanks, I've changed those and modified the category argument to '1,2' (in my case '5,10') but it now lists posts from either category 1 or category two, not only posts in both category one and category two.
February 26, 2017 at 2:19 am #201977Brad DaltonParticipantMarch 2, 2017 at 12:19 am #202314Alec BurnsMemberPerfect, exactly what I needed. Thank you.
March 2, 2017 at 2:26 am #202316archana9MemberYou can modify the WP_Query args in the featured posts widget however you'll loose the changes when Genesis is updated unless you copy over the widget to your child theme.
follow my website
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.