StudioPress Community Forums
  StudioPress Community Forums > Forums > General Discussion
For help and support, access to your downloads, or to manage your account please log into My StudioPress.

These forums have been set to read-only so you can browse the existing topics for any questions you may have.

For general discussion on WordPress, CSS and design (NOT for support) visit the new Community Forums.
 
 
Thread Tools Display Modes
  #1  
Old 09-21-2012, 10:17 PM
golden golden is offline
Registered User
Genesis Member
 
Join Date: Dec 2010
Posts: 268
Default Random Testimonial

I'd like to expand on this by pulling one random testimonial and have it appear in specific page bodies (not widgets). I

My testimonials are individual blog posts with custom fields pulled to one review page. I was hoping this code would work:

Code:
<ul>
<?php query_posts('category_name=Testimonials&showposts=1&offset=0&orderby=rand'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; endif; ?>
</ul>

But it doesn't. I also tried replacing category name with category id=36 . No good.

Any suggestions?

Last edited by GaryJ; 09-24-2012 at 09:59 AM. Reason: Created new thread
  #2  
Old 09-26-2012, 07:59 AM
NicktheGeek's Avatar
NicktheGeek NicktheGeek is offline
Forum Manager
 
Join Date: Feb 2010
Posts: 62,650
Default

Please post a link to one of your testimonials.
__________________
Nick "Fred and/or George Weasley" Croft
Designs by Nick the Geek
@Nick_theGeek on Twitter

Make web design easier, get FireBug for FireFox

Want to learn more about Genesis? Check out my Genesis Explained Series

  #3  
Old 09-30-2012, 11:53 AM
golden golden is offline
Registered User
Genesis Member
 
Join Date: Dec 2010
Posts: 268
Default

Quote:
Originally Posted by NicktheGeek View Post
Please post a link to one of your testimonials.

http://www.pittsburghweddingphotogra...hy-is-amazing/
  #4  
Old 09-30-2012, 06:17 PM
NicktheGeek's Avatar
NicktheGeek NicktheGeek is offline
Forum Manager
 
Join Date: Feb 2010
Posts: 62,650
Default

"category_name" is a mis-nomer. You actually need to use the slug, so try this.
PHP Code:
<?php query_posts('category_name=testimonials&showposts=1&offset=0&orderby=rand'); ?>
__________________
Nick "Fred and/or George Weasley" Croft
Designs by Nick the Geek
@Nick_theGeek on Twitter

Make web design easier, get FireBug for FireFox

Want to learn more about Genesis? Check out my Genesis Explained Series

  #5  
Old 10-03-2012, 10:24 AM
golden golden is offline
Registered User
Genesis Member
 
Join Date: Dec 2010
Posts: 268
Default

HTML Code:
<ul>
<?php query_posts('category_name=testimonials&showposts=1&offset=0&orderby=rand'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; endif; ?>
</ul>
Doesn't work. It shows the code on the page....

@Nick, you said I need to use the slug. All of the page titles are different. I tied them together for the testimonials pge using the categor id 36.
  #6  
Old 10-03-2012, 12:28 PM
NicktheGeek's Avatar
NicktheGeek NicktheGeek is offline
Forum Manager
 
Join Date: Feb 2010
Posts: 62,650
Default

where are you adding this code?
__________________
Nick "Fred and/or George Weasley" Croft
Designs by Nick the Geek
@Nick_theGeek on Twitter

Make web design easier, get FireBug for FireFox

Want to learn more about Genesis? Check out my Genesis Explained Series

  #7  
Old 10-03-2012, 12:35 PM
golden golden is offline
Registered User
Genesis Member
 
Join Date: Dec 2010
Posts: 268
Default

Quote:
Originally Posted by NicktheGeek View Post
where are you adding this code?
I am adding it to the html window in the contact page body below a Gravity Form. I it to pull random testimonials anywhere I have a call to action.
  #8  
Old 10-03-2012, 12:52 PM
NicktheGeek's Avatar
NicktheGeek NicktheGeek is offline
Forum Manager
 
Join Date: Feb 2010
Posts: 62,650
Default

You cannot add PHP to the page content. You might try the Genesis Simple Hooks plugin.
__________________
Nick "Fred and/or George Weasley" Croft
Designs by Nick the Geek
@Nick_theGeek on Twitter

Make web design easier, get FireBug for FireFox

Want to learn more about Genesis? Check out my Genesis Explained Series

  #9  
Old 10-03-2012, 12:55 PM
golden golden is offline
Registered User
Genesis Member
 
Join Date: Dec 2010
Posts: 268
Default

Quote:
Originally Posted by NicktheGeek View Post
You cannot add PHP to the page content. You might try the Genesis Simple Hooks plugin.
Can Genesis Simple Hooks allow me to have the testimonials appear on specific pages rather than all? If so, under which Genesis Hooks heading should I add the code?
  #10  
Old 10-03-2012, 02:00 PM
NicktheGeek's Avatar
NicktheGeek NicktheGeek is offline
Forum Manager
 
Join Date: Feb 2010
Posts: 62,650
Default

you can make your code conditional
http://nickc.co/conditional-content

I would recommend the genesis_post_content hook.
__________________
Nick "Fred and/or George Weasley" Croft
Designs by Nick the Geek
@Nick_theGeek on Twitter

Make web design easier, get FireBug for FireFox

Want to learn more about Genesis? Check out my Genesis Explained Series

  #11  
Old 10-03-2012, 02:28 PM
golden golden is offline
Registered User
Genesis Member
 
Join Date: Dec 2010
Posts: 268
Default

I originally wanted this on specific pages, but it seems difficult. So, I am going to see what it looks like on all pages but the home page. Here is what I have based on Nick's tutorial.

I am sure I have the first opening & closing tags messed up.
HTML Code:
<ul>
<?php
if(!is_home()) { ?> <?php }
?>
<?php query_posts if(is_contact()) { ?>('category_name=testimonials&showposts=1&offset=0&orderby=rand'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; endif; ?>
</ul>
  #12  
Old 10-03-2012, 02:54 PM
NicktheGeek's Avatar
NicktheGeek NicktheGeek is offline
Forum Manager
 
Join Date: Feb 2010
Posts: 62,650
Default

yea, you need to wrap your code in the conditional
PHP Code:
<?php if(!is_home()) { ?>
<ul>
<?php query_posts if(is_contact()) { ?>('category_name=testimonials&showposts=1&offset=0&orderby=rand'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; endif; ?>
</ul>
<?php ?>
__________________
Nick "Fred and/or George Weasley" Croft
Designs by Nick the Geek
@Nick_theGeek on Twitter

Make web design easier, get FireBug for FireFox

Want to learn more about Genesis? Check out my Genesis Explained Series

  #13  
Old 10-03-2012, 03:54 PM
golden golden is offline
Registered User
Genesis Member
 
Join Date: Dec 2010
Posts: 268
Default

I want it to appear at the bottom of the page body.

I added the cod to the Genesis Before Footer Hook and clicked enable php.

Parse error: syntax error, unexpected T_IF in /home/goldenim/public_html/pittsburghweddingphotographer.com/wp-content/plugins/genesis-simple-hooks/plugin.php(126) : eval()'d code on line 3
  #14  
Old 10-03-2012, 04:18 PM
NicktheGeek's Avatar
NicktheGeek NicktheGeek is offline
Forum Manager
 
Join Date: Feb 2010
Posts: 62,650
Default

I missed some of your broken conditional code
PHP Code:
<?php if(!is_home()) { ?>
<ul>
<?php query_posts('category_name=testimonials&showposts=1&offset=0&orderby=rand'); ?>
<?php 
if (have_posts()) : while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; endif; ?>
</ul>
<?php ?>
__________________
Nick "Fred and/or George Weasley" Croft
Designs by Nick the Geek
@Nick_theGeek on Twitter

Make web design easier, get FireBug for FireFox

Want to learn more about Genesis? Check out my Genesis Explained Series

  #15  
Old 10-03-2012, 06:53 PM
golden golden is offline
Registered User
Genesis Member
 
Join Date: Dec 2010
Posts: 268
Default

This code works but is showing on the home page. Also, I wanted to pull the whole post and this only pulls the title link.
  #16  
Old 10-03-2012, 08:38 PM
NicktheGeek's Avatar
NicktheGeek NicktheGeek is offline
Forum Manager
 
Join Date: Feb 2010
Posts: 62,650
Default

instead of is_home() use is_front_page()

If you will want more info use something like the_content() or other loop functions.
__________________
Nick "Fred and/or George Weasley" Croft
Designs by Nick the Geek
@Nick_theGeek on Twitter

Make web design easier, get FireBug for FireFox

Want to learn more about Genesis? Check out my Genesis Explained Series

  #17  
Old 10-03-2012, 08:57 PM
golden golden is offline
Registered User
Genesis Member
 
Join Date: Dec 2010
Posts: 268
Exclamation

genesis_after_content Hook

HTML Code:
<?php if is_front_page()) { ?>
<ul>
<?php query_posts('category_name=testimonials&showposts=1&offset=0&orderby=rand'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; endif; ?>
</ul>
<?php } ?>
Parse error: syntax error, unexpected T_STRING, expecting '(' in /home/goldenim/public_html/pittsburghweddingphotographer.com/wp-content/plugins/genesis-simple-hooks/plugin.php(126) : eval()'d code on line 1

  #18  
Old 10-04-2012, 07:58 AM
NicktheGeek's Avatar
NicktheGeek NicktheGeek is offline
Forum Manager
 
Join Date: Feb 2010
Posts: 62,650
Default

you removed the ( after if
__________________
Nick "Fred and/or George Weasley" Croft
Designs by Nick the Geek
@Nick_theGeek on Twitter

Make web design easier, get FireBug for FireFox

Want to learn more about Genesis? Check out my Genesis Explained Series

  #19  
Old 10-04-2012, 09:38 AM
golden golden is offline
Registered User
Genesis Member
 
Join Date: Dec 2010
Posts: 268
Default

Quote:
Originally Posted by NicktheGeek View Post
you removed the ( after if
I searched the code on this whole thread. There is no after if. Should I add it like this?

HTML Code:
<?php endwhile; endif; afterif ?>
  #20  
Old 10-04-2012, 12:24 PM
NicktheGeek's Avatar
NicktheGeek NicktheGeek is offline
Forum Manager
 
Join Date: Feb 2010
Posts: 62,650
Default

not fterif; after the "if" you removed the (. If is a function so it should have if() with the code you are testing against inside the (). You removed the ( so you have if )
__________________
Nick "Fred and/or George Weasley" Croft
Designs by Nick the Geek
@Nick_theGeek on Twitter

Make web design easier, get FireBug for FireFox

Want to learn more about Genesis? Check out my Genesis Explained Series

  #21  
Old 10-04-2012, 12:28 PM
golden golden is offline
Registered User
Genesis Member
 
Join Date: Dec 2010
Posts: 268
Default

Quote:
Originally Posted by NicktheGeek View Post
not fterif; after the "if" you removed the (. If is a function so it should have if() with the code you are testing against inside the (). You removed the ( so you have if )

I'm sorry, I know basic html. Would you kindly merge this advice with the whole php code so I can see how it should look? I'm sure it feels spoon fed to you, but I am trying to learn. :)

Thank you for your continued responses Nick.
  #22  
Old 10-04-2012, 01:00 PM
NicktheGeek's Avatar
NicktheGeek NicktheGeek is offline
Forum Manager
 
Join Date: Feb 2010
Posts: 62,650
Default

You are missing the (. I've added it in red so you can see what I'm trying to explain.
Code:
<?php if( is_front_page() ) { ?>
<ul>
<?php query_posts('category_name=testimonials&showposts=1&offset=0&orderby=rand'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; endif; ?>
</ul>
<?php } ?>
__________________
Nick "Fred and/or George Weasley" Croft
Designs by Nick the Geek
@Nick_theGeek on Twitter

Make web design easier, get FireBug for FireFox

Want to learn more about Genesis? Check out my Genesis Explained Series

 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Testimonial/Quotes Plugin... dawud.miracle General Discussion 1 04-14-2011 02:43 PM
Testimonial Plugin? TyyWard General Discussion 1 01-29-2011 05:16 PM


All times are GMT -5. The time now is 03:53 PM.

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.