WordPress.org

Ready to get started?Download WordPress

Forums

Testimonials by Aihrus
[resolved] Display on page without widget (10 posts)

  1. Tom Combs
    Member
    Posted 1 year ago #

    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(); ?>

    http://wordpress.org/extend/plugins/testimonials-widget/

  2. Michael Cannon
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  3. Tom Combs
    Member
    Posted 1 year ago #

    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!

  4. Michael Cannon
    Member
    Plugin Author

    Posted 1 year ago #

    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

  5. ul71m0
    Member
    Posted 1 year ago #

    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...

  6. Michael Cannon
    Member
    Plugin Author

    Posted 1 year ago #

    What URL, theme and shortcode are you using?

  7. ul71m0
    Member
    Posted 1 year ago #

    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...

    http://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;
                        ?>
  8. Michael Cannon
    Member
    Plugin Author

    Posted 1 year ago #

    Shouldn't $loop be $the_query?

  9. ul71m0
    Member
    Posted 1 year ago #

    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;
                        ?>
  10. Michael Cannon
    Member
    Plugin Author

    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.