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 }; ?>
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?
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”.
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.
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 }; ?>
@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()
?
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?
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.
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.
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; ?>
Wow, Michael. Thank you. It works. Couldn’t have done it without your help.
Wonderful. 😀 Don’t forget to give YARPP a star rating in the plugins directory. 🙂