• Resolved ChrisHPZ

    (@chrishpz)


    Hi there. Through the help of the developers of this plugin, I was able to implement a change in how categories and their listings are displayed. What I would like to ultimately do is show Categories and only featured listings in each category. Is this possible? One thing that could help is to know how to specifically target “featured listings” A representation of what we’re trying to do is as follows:

    Category Name:
    Featured Listing
    Don’t display non-featured listings

    Category Name:
    Featured Listing
    Don’t display non-featured listings

    The code I have is below.

    <?php
        $categories = get_terms(  WPBDP_CATEGORY_TAX, 'hide_empty=0' );
        ?>
    
    <ul>
                <?php
                foreach ( $categories as $category ):
                        $listings = get_posts( array( 'post_type' => WPBDP_POST_TYPE,
                                                                                  'tax_query' => array( array(
                                                                                        'taxonomy' => WPBDP_CATEGORY_TAX,
                                                                                        'field' => 'id',
                                                                                        'terms' => $category->term_id  )  ) ) );
                ?>
    
    <li>
                        <!-- Category title & link -->
                        <a>"><?php echo $category->name; ?></a>
    
                        <!-- Listings under category (only listing title & link) -->
                        <ul class="listings">
                        <?php foreach ( $listings as $listing ): ?>
                                </li>
    <li><a>ID ); ?>"><?php echo $listing->post_title; ?></a></li>
                        <?php endforeach; ?>
                        </ul>
                <?php endforeach; ?>

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    http://wordpress.org/plugins/business-directory-plugin/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Business Directory Plugin

    (@businessdirectoryplugin)

    Hi ChrisHPZ,

    Since we already do something like this in the featured listing widget, you might try leveraging the code in there, filtering by category as well as the featured flag.

    Have you checked that example out yet?

    Thread Starter ChrisHPZ

    (@chrishpz)

    Well I do use the Featured Listings widget in the main directory page but it only shows the listings, not the categories. I suppose I could alter the featured listings function though. Would you be so kind as to point out the files I should look at?

    Plugin Author Business Directory Plugin

    (@businessdirectoryplugin)

    Hi Chris,

    My developer said to do this:

    Featured listings have a metadata key called “_wpbdp[sticky]” set to “sticky”. That’s how he can obtain them using get_posts just as he’s already doing. Something like the following should work:

    <br />
    $listings = get_posts( array(<br />
        'post_type' => WPBDP_POST_TYPE,<br />
        'tax_query' => array( array(<br />
            'taxonomy' => WPBDP_CATEGORY_TAX,<br />
            'field' => 'id',<br />
            'terms' => $category->term_id ) ),<br />
        'meta_query' => array( array(<br />
            'key' => '_wpbdp[sticky]',<br />
            'value' => 'sticky' ) )<br />
    ) );<br />

    The Featured Listings widget does exactly that (with no category specified).

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display Categories and Featured Listings only’ is closed to new replies.