• Hi!
    I just started using the Dyad theme and it looks pretty sweet!
    The website I’m working on now is based upon two categories of posts. Is there any way to add a Featured Post to the Category?

    I’ll explain a little closer:
    In the menu two of the links are to categories, not pages. Could these have the same feature as the front page? So when you go to Category 1 Post 1 will be the featured post and on Category 2 Post 2 will be the featured post.

    Thanks in advance!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @ch3600!

    The functionality you’re after is possible to achieve but will require you to play about with HTML and basic PHP. If you’re comfortable with doing that, the very first step is for you to follow the guidance here to set up a child theme:

    https://codex.www.ads-software.com/Child_Themes

    If you’d like some more background about what child themes actually are and how they work, I recommend these resources:

    https://www.smashingmagazine.com/2016/01/create-customize-wordpress-child-theme/

    After you have created your child theme, duplicate the parent’s header.php file in your child theme’s directory.

    Locate the following code in that file:

    <?php if ( is_home() || is_front_page() || ( is_single() && 'image' == get_post_format() ) ) : ?>
    	<div class="featured-content">
    		<?php get_template_part( 'template-parts/loop', 'banner' ); ?>
    	</div>
    <?php endif; ?>

    The above code is telling the theme to display a banner at the top of any page it detects to be a home page or a single post with the image post format assigned to it.

    You could make use of a conditional tag to expand the types of pages that this rule applies to.

    For example, adding is_category() would add a banner to your category pages:

    <?php if ( is_home() || is_front_page() || ( is_single() && 'image' == get_post_format() ) || is_category() ) : ?>
    	<div class="featured-content">
    		<?php get_template_part( 'template-parts/loop', 'banner' ); ?>
    	</div>
    <?php endif; ?>

    Next, duplicate the parent’s /template-parts/loop-banner.php file to your child theme’s directory.

    In this file, we can see the type of banner that the theme displays for each type of page. If you’d like to change the type of banner that’s displayed on your category pages, this is where you can do it.

    Let me know if that helps to point you in the right direction. If you let me know the URL of your site and how you’d like your category pages to look specifically, I can guide you further.

    Thread Starter ch3600

    (@ch3600)

    Hi again!
    Thank you for your response. This worked great and I now have the featured image available on both category pages + main page.
    Is there any way of getting a different featured post on the two pages?
    https://www.hamremoen.no
    Say that I want post 1 to be the featured post on category 1 (/category/inn-pa-tunet/) and post 2 featured post on category 2 (/category/andelsgard/) how could I do this? I’m guessing that I would need to create another tag that could be used?
    Would it then also for both post 1 and post 2 to be featured on a slider on the home page?

    Thanks again for your help!

    Hi @ch3600,

    I’m glad that you now have the featured post slider on category pages as well as your main page. ??

    Creating separate featured post sliders for different categories would take some more work and requires some more knowledge of HTML and PHP, which goes beyond what we can support via this forum.

    As a starting point, I recommend looking at the parent’s /template-parts/loop-banner.php and /template-parts/content-featured-post.php files to see how the current slider is set up. You can then attempt to duplicate this for category pages and use conditional tags in your header.php file to decide which slider displays on which type of page on your site.

    Let us know how you get on with that!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Featured Post for categories’ is closed to new replies.