WordPress.org

Ready to get started?Download WordPress

Forums

Yet Another Related Posts Plugin (YARPP)
[resolved] New HTML output ruins my custom template (8 posts)

  1. gates
    Member
    Posted 1 year ago #

    All YARPP output is now wrapped in a div with class yarpp-related, yarpp-related-widget, or yarpp-related-rss as appropriate (by request). If there are no results, a yarpp-related-none class is added.

    Well, I can't believe that this request got implemented in 4.0 since it can easily be coded by any user. Now my complicated template is broken (which uses 3 tabs for related OR random posts / new posts / popular posts). By inserting the div it breaks. I had a backup so I went back to the previous version. Please remove it (at least for posts with custom templates) or help me to get rid of it.

    I really like this plugin, so it would be a bummer if I can't upgrade anymore.

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

  2. gates
    Member
    Posted 1 year ago #

    By the way, the custom template has only the related/random feature in it and the rest of the tabs (new and popular posts) are in single.php. It can't be placed in the custom yarpp template as one complete function, because it will cause issues that I can't debug. That's why the div breaks my HTML... it'll be placed in a random place of my HTML.

  3. mitcho (Michael Yoshitaka Erlewine)
    Member
    Plugin Author

    Posted 1 year ago #

    I'm really sorry to hear that this change adversely affected your theme. This is the first issue I've heard of where something has actually broken because of this, and no issues were reported with the beta releases which had this change. But alas... thanks for bringing this to my attention now.

    I'd like to better understand this issue. Could you tell me what your custom template's structure is, such that adding this div was a problem? As I understand it, YARPP's template covers the "related/random posts" section, while the other two sections are in your theme. Since this one section seems contained to a particular subtree of the HTML structure, adding a div wrapper might unfortunately affect some CSS styling, but I don't think that's unfixable.

  4. gates
    Member
    Posted 1 year ago #

    It is unfixable because the opening div starts in an ul and the closing div will be placed outside this unordered list and actually closes another div (.tabcontainer) that shouldn't be closed. That's what I remember... I'm afraid to try it again, because downgrading caused an issue in the database, so I put a backup of my database back. Here is the code:

    The part in single.php

    <!-- [START] Related/Random, Popular and New Posts -->
    					<div id="suggestions">
    						<ul id="vertical-tabs" class="idTabs">
    
    							<?php related_posts(); ?>
    
    							<!-- Popular Posts -->
    							<?php
    								// Popular Posts plugin - outputs an unordered list
    								if (function_exists('wpp_get_mostpopular')) wpp_get_mostpopular("wpp_end='</ul>'&wpp_start='<ul id=\"popular-content\">'&stats_date=1&stats_date_format='d/m/Y'&range='weekly'&order_by=views&stats_comments=0&limit=4&post_type=post,quiz");
    							?>
    							<!-- /Popular Posts -->
    
    					  		<!-- Latest Posts -->
    							<ul id="new-content">
    							<?php
    								$args = array(
    											'post_type' => array( 'post', 'quiz', 'book' ),
    											'showposts' => 4,
    											'order' => 'DESC'
    											);
    								$latestPosts = new WP_Query();
    								$latestPosts->query( $args );
    							?>
    							<?php while ($latestPosts->have_posts()) : $latestPosts->the_post(); ?>
    								<li><h5><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h5> <small><?php the_category(', ') ?></small></li>
    							<?php endwhile; ?>
    							<?php // http://codex.wordpress.org/Class_Reference/WP_Query#Interacting_with_WP_Query
    								wp_reset_postdata(); ?>
    							</ul>
    							<!-- /Latest Posts -->
    
    						</div><!-- .tabcontainer -->
    
    					</div><!-- suggestions -->
    					<!-- [END] Related/Random, Popular and New Posts -->

    My custom YARPP template (with an if statement to display random posts when there are no related posts).

    <?php if (have_posts()):?>
    							<li><a href="#related-content">Related</a></li>
    							<li><a href="#popular-content">Popular</a></li>
    							<li><a href="#new-content">Latest</a></li>
    						</ul><!-- #vertical-tabs.idTabs -->
    
    						<div class="tabcontainer clearfix">
    							<ul id="related-content">
    	  						<?php while (have_posts()) : the_post(); ?>
    	  							<li><h5><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h5> <small><?php the_category(', ') ?></small></li>
    	  						<?php endwhile; ?>
    							</ul>
    <?php else: ?>
    							<li><a href="#random-content">Random</a></li>
    							<li><a href="#popular-content">Popular</a></li>
    							<li><a href="#new-content">Latest</a></li>
    						</ul><!-- #vertical-tabs.idTabs -->
    
    						<div class="tabcontainer clearfix"> 
    
    							<!-- Random Posts -->
    							<ul id="random-content">
    							<?php
    								$args = array(
    											'post_type' => array( 'post', 'quiz', 'book' ),
    											'showposts' => 4,
    											'orderby' => 'rand'
    											);
    								$randomPosts = new WP_Query();
    								$randomPosts->query( $args );
    							?>
    							<?php while ($randomPosts->have_posts()) : $randomPosts->the_post(); ?>
    								<li><h5><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h5> <small><?php the_category(', ') ?></small></li>
    	  						<?php endwhile; ?>
    	  						<?php // http://codex.wordpress.org/Class_Reference/WP_Query#Interacting_with_WP_Query
    	  							wp_reset_postdata(); ?>
    							</ul>
    							<!-- /Random Posts -->
    
    <?php endif; ?>
  5. Mat43b
    Member
    Posted 1 year ago #

    Hi, I also have a problem with custom templates. It broke some divs in my theme, but then I solved it by editing the codes.

    But what really bothers me is that it now displays the threshold variable before the custom template. There's no code in the custom template to echo that variable, but for some reason it shows up right above the words "Related Posts". Can you take a look at this? I've been banging my head trying to find in your code where that echo/print variable is, but I still could not locate it. It works fine with your pre-made templates, just the custom ones that's giving me trouble.

  6. mitcho (Michael Yoshitaka Erlewine)
    Member
    Plugin Author

    Posted 1 year ago #

    @gates I see what you're doing there... I never anticipated that a YARPP custom template would close one open tag and open another.

    Here's how you could do what you're doing with YARPP 4: take the part where you print the vertical-tabs outside of the YARPP template. Use related_posts_exist() to decide whether to print "Related" or "Random" in that tab title, and if random, do the random post computation outside of YARPP's custom template. If related_posts_exist() is true, just call YARPP to get the content inside that tabcontainer.

    @Mat43b: can you post the resulting HTML and/or your custom theme so I can take a look? This is a curious report and I'd love to get it resolved.

  7. gates
    Member
    Posted 1 year ago #

    Thanks! I actually didn't know about the existence of related_posts_exist(). After some editing I got it right. I'm not a real PHP expert, so some simple if statements were doable. Now, the whole unordered list is/the tabs themselves are wrapped in the YARPP-div. However, the YARPP-div is still unnecessary code (read: dirty html).

  8. mitcho (Michael Yoshitaka Erlewine)
    Member
    Plugin Author

    Posted 1 year ago #

    @gates understood on the dirty html point. It's certainly a win for the list and new thumbnails views, and for custom templates, hopefully from now on new templates can be written with that in mind.

    Thanks again for your report! Glad it's resolved. :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.