• Resolved Tom Combs

    (@tcwebguru)


    This isn’t a request, it’s a solution I came up with that others may find useful.

    I wanted to pull the testimonials into a page using a custom query that would use my global css, instead of using the shortcode or the php call to the widget.

    The code below usually works by using ‘category’ => ‘category-name’ , but when I used my category name ‘testimonials’, the query pulled all of my posts in to the page.

    I removed the category argument and replaced it with post_type and it works perfectly now.

    Hope this can help others too.


    <?php
    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    $args = array( 'paged' => $paged, 'posts_per_page' => 10, 'orderby' => DESC, 'post_type' => Testimonials_Widget::pt );
    // The Query
    query_posts( $args );
    // The Loop
    while ( have_posts() ) : the_post(); ?>

    https://www.ads-software.com/extend/plugins/testimonials-widget/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Contributor Michael Cannon

    (@comprock)

    Thank you very much for the suggestion. I’ve added FAQ entry #30 credited to you. It’ll become available with the next Testimonials Widget release.

    Thread Starter Tom Combs

    (@tcwebguru)

    Thanks Michael!
    Great plugin by the way.

    If only all of the plugin developers responded as quickly as you do.
    Keep up the good work!

    Plugin Contributor Michael Cannon

    (@comprock)

    Tom,

    You’re very welcome. I have to admit that I don’t work a real job. I spend most of my time coding, cycling, eating, sleeping, and traveling the world or thinking about them. ??

    Ciao!

    Michael

    Im trying to show testimonials from specific category on that category page, its not in single post or page its on category page. And when i add your code i get error because there is no endwhile, so i add it and than page loads but there is no content in testimonials. Than i added the_content(); and i get just one testimonial.

    What i want to accomplish is that query somehow knows on what category is and show all testimonials from that category…

    Plugin Contributor Michael Cannon

    (@comprock)

    What URL, theme and shortcode are you using?

    Im not using shortcode i need to do it with query because its development site and i don`t know what categories will be there and i need to make it all dynamic. I have categories with sub-categories. Every subcategory will have:

    1. Sticky post
    2. Regular posts
    3. Testimonials

    So i have to show testimonials on subcategories page. When user creates new testimonial it will select proper category…

    https://dev.fabricit.com/alex/mills/case-studies/category-1/ im testing on this page now and in the bottom or the page i need to have testimonials rotating. Rotating isn`t problem problem is to show them…

    I tried with this code but no luck, i get error

    Catchable fatal error: Object of class stdClass could not be converted to string in /home/devfit/public_html/alex/mills/wp-includes/query.php on line 1450

    <?php
                global $post;
                $category = get_the_category( $post->ID );
                $args = array(
                    'cat' => $category,
                    'post_type' => Testimonials_Widget::pt,
                    'posts_per_page' => 10,
                    'orderby' => DESC
                );
    
                $the_query = new WP_Query( $args );
                while ( $loop->have_posts() ) : $loop->the_post();
                    the_title();
                    echo '<div class="entry-content">';
                    the_content();
                    echo '</div>';
                endwhile;
                        ?>
    Plugin Contributor Michael Cannon

    (@comprock)

    Shouldn’t $loop be $the_query?

    same error with this code:

    <?php
                global $post;
                $category = get_the_category( $post->ID );
                $args = array(
                    'cat' => $category,
                    'post_type' => Testimonials_Widget::pt,
                    'posts_per_page' => 10,
                    'orderby' => DESC
                );
    
                $the_query = new WP_Query( $args );
                while ( $the_query->have_posts() ) : $the_query->the_post();
                    the_title();
                    echo '<div class="entry-content">';
                    the_content();
                    echo '</div>';
                endwhile;
                        ?>
    Plugin Contributor Michael Cannon

    (@comprock)

    Have you debugged your code to ensure that $category and $the_query are valid?

    Next you can add something echo __LINE__ . ':' . basename( __FILE__ ) . '<br />'; after each line to specifically locate where the problem comes from.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Display on page without widget’ is closed to new replies.