WordPress.org

Ready to get started?Download WordPress

Forums

Yet Another Related Posts Plugin (YARPP)
[resolved] [Plugin: Yet Another Related Posts Plugin] Yarrp for Related Terms on Glossary Page (13 posts)

  1. ubergiant
    Member
    Posted 1 year ago #

    I haven't been able to get Yarrp working how I want for a glossary. No related pages are ever shown and the random one for when no terms are similar (currently always the case) is a post (which should only be a page that is a random glossary term.)

    Basically want to display only pages within the glossary. I've got Yarrp displaying on the right pages.

    Here's an example page: http://www.lolguides.com/glossary/ad

    My custom template:

    <?php if ($post->post_parent != '86') {; //if not glossary ?>
    
    <h4>Other Posts That May Help You</h4>
    <?php if (have_posts()):?>
    	<ol>
    		<?php while (have_posts()) : the_post(); ?>
    		<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><!-- (<?php the_score(); ?>)--></li>
    		<?php endwhile; ?>
    	</ol>
    <?php else:
    query_posts("orderby=rand&order=asc&limit=1");
    the_post();?>
    	<p>No related posts were found so here's a random one: <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></p>
    <?php endif; ?>
    
    <?php } else {; // if glossary ?>
    
    <h4>Related Terms</h4>
    <?php if (have_posts()):?>
    	<ol>
    		<?php while (have_posts()) : the_post(); ?>
    		<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><!-- (<?php the_score(); ?>)--></li>
    		<?php endwhile; ?>
    	</ol>
    <?php else:
    query_posts("orderby=rand&order=asc&limit=1");
    the_post();?>
    	<p>No related terms were found so here's a random one: <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></p>
    <?php endif; ?>
    <?php }; ?>

    Ideas Michael? Thanks, been using your script for years on other sites.

    http://wordpress.org/extend/plugins/yet-another-related-posts-plugin/

  2. ubergiant
    Member
    Posted 1 year ago #

    Noticed you answered other support questions, but not this Michael. I'm still in need of help so hope you can provide support.

    I've used YARPP Experiments. 98.37% is cached. I guessed the custom template is not coded to retrieve pages instead of posts.

    So I've updated the template to the following and now get the same three pages suggested for every page:

    <?php if ($post->post_parent != '86') {; //if not glossary ?>
    
    <h4>Other Posts That May Help You</h4>
    <?php if (have_posts()):?>
    	<ol>
    		<?php while (have_posts()) : the_post(); ?>
    		<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><!-- (<?php the_score(); ?>)--></li>
    		<?php endwhile; ?>
    	</ol>
    <?php else:
    query_posts("orderby=rand&order=asc&limit=1");
    the_post();?>
    	<p>No related posts were found so here's a random one: <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></p>
    <?php endif; ?>
    
    <?php } else {; // if glossary ?>
    
    <h4>Related Terms</h4>
    
    <?php if (get_pages("author=1")) :; query_posts(array('showposts' => '3', 'post_parent' => '86', 'post_type' => 'page')); ?>
    	<ol>
    		<?php while (have_posts()) : the_post(); ?>
    		<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><!-- (<?php the_score(); ?>)--></li>
    		<?php endwhile; ?>
    	</ol>
    <?php wp_reset_query();
    else: query_posts("orderby=rand&order=asc&limit=1"); the_post();?>
    	<p>No related terms were found so here's a random one: <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></p>
    <?php endif; ?>
    <?php }; ?>
  3. mitcho (Michael Yoshitaka Erlewine)
    Member
    Plugin Author

    Posted 1 year ago #

    Hope I can still help you out, but I'm a little confused by what you're trying to do.

    If you want to display pages, you should make sure to be calling this using the related_pages() function. Is that what you're doing?

    As for the same three pages showing up under all posts: are these showing up as "Other posts that may help you" or as part of your random other entries?

  4. ubergiant
    Member
    Posted 1 year ago #

    I am using the related pages function. On page.php in the template, I have:

    <?php if ($post->post_parent == '86') { related_pages(); }; // use YARPP plugin only on pages with glossary parent ?>

    That part works fine. What are you confused by? I've tried to explain the problem, but might be able to explain further if you say what is confusing.

    The same three pages are showing up under all posts as part of the "other posts that may help you".

  5. mitcho (Michael Yoshitaka Erlewine)
    Member
    Plugin Author

    Posted 1 year ago #

    Okay, I see. So it only gets called if $post->post_parent is 86; in other words, if it's a glossary page.

    Now note that in your code you have a section for glossaries and non-glossaries. And in the glossary case, you're not using YARPP at all: query_posts(array('showposts' => '3', 'post_parent' => '86', 'post_type' => 'page')); You're not actually calling the YARPP results at all.

  6. ubergiant
    Member
    Posted 1 year ago #

    With regards to your first paragraph, correct.

    I had no idea in the glossary case, YARPP results were not being used. I did that because all the template examples recommend posts, not pages.

    So the glossary case now has the following, but it just recalls posts, not pages yet alone pages pertaining to the glossary parent page. I am stumped.

    <h4>Related Terms</h4>
    
    <?php if (have_posts()):?>
    	<ul id="relatedterms">
    		<?php while (have_posts()) : the_post(); ?>
    		<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><!-- (<?php the_score(); ?>)--></li>
    		<?php endwhile; ?>
    	</ul>
    <?php else: ?>
    	<p>No related terms were found so here's a random one: <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></p>
    <?php endif; ?>
    <?php }; ?>
  7. mitcho (Michael Yoshitaka Erlewine)
    Member
    Plugin Author

    Posted 1 year ago #

    @ubergiant: the code there is your YARPP template, correct? What things get displayed here as "related" depends on your YARPP settings and how you're calling the YARPP code, not the code in the template.

    Are you calling YARPP using related_pages()?

  8. ubergiant
    Member
    Posted 1 year ago #

    Yes, that's a part of the YARPP template.

    I said before, just posts gets displayed. I made a mistake. Sorry for the confusion. Pages are being displayed now! They are all pages though.

    And yes, related_pages(); is being used (see my second previous post for the code).

    The issue now is how can I get only pages with the page parent id of 86 (glossary pages) to display instead of all the pages?

  9. mitcho (Michael Yoshitaka Erlewine)
    Member
    Plugin Author

    Posted 1 year ago #

    Let me get this straight: so you want all your related "items" that are displayed to be pages with parent id 86?

    If so, what you want to do is check for the parent page being 86 *within* your while(have_posts()) : the_post(); loop in your YARPP template. If the page parent is 86, display it, else print some other HTML or no HTML. Hope that makes sense.

  10. ubergiant
    Member
    Posted 1 year ago #

    Correct.

    I see. Implemented your suggestion and it's a step forward.

    <?php if (have_posts()):?>
    	<ul id="relatedterms">
    		<?php while (have_posts()) : the_post(); ?>
    		<?php if ($post->post_parent == '86') { ?>
    		<li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><!-- (<?php the_score(); ?>)--></li>
    		<?php }; ?>
    		<?php endwhile; ?>
    	</ul>
    <?php else: ?>
    	<p>No related terms were found so here's a random one: <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></p>
    <?php endif; ?>
    <?php }; ?>

    The one problem is when there are ONLY related pages that are not of the parent id 86. Nothing is displayed i.e. the "else" part of the loop is not triggered.

  11. mitcho (Michael Yoshitaka Erlewine)
    Member
    Plugin Author

    Posted 1 year ago #

    For that, I would suggest you keep a counter to see whether anything was actually displayed. Something like:

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]

    <?php
    $displayed = 0;
    if (have_posts()):?>
    	<ul id="relatedterms">
    		<?php while (have_posts()) : the_post(); ?>
    		<?php if ($post->post_parent == '86') { ?>
    		<?php $displayed++; ?>
    
    <li><a>" rel="bookmark"><?php the_title(); ?></a><!-- (<?php the_score(); ?>)--></li>
    		<?php }; ?>
    		<?php endwhile; ?>
    
    <?php endif; ?>
    
    <?php if ($displayed == 0): ?>
    	<p>No related terms were found so here's a random one: <a>" rel="bookmark"><?php the_title(); ?></a></p>
    <?php endif; ?>
  12. ubergiant
    Member
    Posted 1 year ago #

    Wow, Michael. Thank you. It works. Couldn't have done it without your help.

  13. mitcho (Michael Yoshitaka Erlewine)
    Member
    Plugin Author

    Posted 1 year ago #

    Wonderful. :D Don't forget to give YARPP a star rating in the plugins directory. :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.