WordPress.org

Ready to get started?Download WordPress

Forums

Contextual Related Posts
[resolved] Related post unwantedly included in post exerpts (36 posts)

  1. ASBG
    Member
    Posted 7 months ago #

    Thanks for the great plugin

    I have a page that displays my posts with thumbnails and excerpts chronologically.

    Since installing the plugin each entry now displays related posts. You can see what I mean here.

    http://australian-sports-betting-guide.com.au/founders-blog/

    I have only selected Add related posts to: pages and feeds (and I tried de-selecting feeds but that does not do anything).

    How do I stop related post showing for every entry on this page?

    Cheers

    http://wordpress.org/plugins/contextual-related-posts/

  2. Ajay
    Member
    Plugin Author

    Posted 7 months ago #

    Do you know the page id (It's the number similar to post id) of founders-blog?

    You can add this in the "Exclude display on" under output options.

  3. ASBG
    Member
    Posted 7 months ago #

    No good I'm afraid. That stops the related posts coming up at the bottom of that page but it does not stop them displaying for every single post excerpt on the page, which what I am trying to do.

  4. Ajay
    Member
    Plugin Author

    Posted 7 months ago #

    How exactly are you generating this page? I mean, what is the code behind this?

    And what if you uncheck pages as well?

  5. ASBG
    Member
    Posted 7 months ago #

    What code id behind it is not straightforward. The theme has a page builder where I just
    chose element > Blog
    If I switch from page builder to classic editor, text the corresponding code is

    [blog show_blog_aux="yes" blog_type="mini" item_count="10" category="all" show_title="yes" show_excerpt="yes" show_details="yes" excerpt_length="40" content_output="excerpt" show_read_more="no" pagination="yes" width="1/1" el_position="first last"]

    If I deselect
    Add related posts to: pages
    that does stops related posts displaying for every single post excerpt on the page.

  6. Ajay
    Member
    Plugin Author

    Posted 7 months ago #

    To be frank, I am not sure on an easier solution other than to disable the automatic insert and use the manual install.

    Can you check with the theme developer how exactly they convert the shortcode to the posts? Because I am not sure what the exclusion criteria would be in this case.

  7. ASBG
    Member
    Posted 7 months ago #

    I asked the developer and they said

    "The blog shortcode can be found in \includes\page-builder\composer\lib\shortcodes\blog.php, he can take a look at the code in there."

  8. Ajay
    Member
    Plugin Author

    Posted 7 months ago #

    Can you send this file to me?

    Please send me the file via: http://ajaydsouza.com/contact/ in a zip file

  9. ASBG
    Member
    Posted 7 months ago #

    okay I just sent it in a .zip I think this is the path

    http://australian-sports-betting-guide.com.au/wp-content/themes/flexform/includes/page-builder/composer/lib/shortcodes/blog.php

    but I get an error when I load it

  10. Ajay
    Member
    Plugin Author

    Posted 7 months ago #

    You can't access blog.php directly from your browser.

    I've received your email but won't be able to look at this until late. I'll check and respond to you with a solution if possible.

  11. ASBG
    Member
    Posted 7 months ago #

    I have a clue!

    They are showing up because the text above them is a custom excerpt. I posted a post without a custom excerpt and related content did not show up. Then I added the customer exert and they show up.

    So how do I set the plug in to not add related posts to custom excerpts?

    Thanks

  12. Ajay
    Member
    Plugin Author

    Posted 6 months ago #

    Hi,

    I checked out the file you sent me. It references a function called: sf_get_post_item
    Can you get the code for that?

  13. ASBG
    Member
    Posted 6 months ago #

    Sure, where would it be?

  14. Ajay
    Member
    Plugin Author

    Posted 6 months ago #

    I can't say for sure as to which file this is in. First place you should try is the functions.php of the theme.

  15. ASBG
    Member
    Posted 6 months ago #

    Well this is raucous barrel of laughs lol.

    Ctrl F in archive.PHP finds 2 instances of sf_get_post_item

    Its also in
    blog.php
    category.php
    index.php
    sf-post-formats.php

    here I hope is the relevant code from archive.php.

    <!-- OPEN page -->
    	<?php if ($sidebar_config == "left-sidebar" || $sidebar_config == "right-sidebar") { ?>
    	<div class="archive-page span8 clearfix">
    	<?php } else if ($sidebar_config == "both-sidebars") { ?>
    	<div class="archive-page row clearfix">
    	<?php } else { ?>
    	<div class="archive-page clearfix">
    	<?php } ?>
    
    		<?php if ($sidebar_config == "both-sidebars") { ?>
    
    			<div class="page-content span6 clearfix">
    
    				<?php if(have_posts()) : ?>
    
    					<div class="blog-wrap">
    
    						<!-- OPEN .blog-items -->
    						<ul class="blog-items <?php echo $list_class; ?> clearfix">
    
    						<?php while (have_posts()) : the_post(); ?>
    
    							<?php
    								$post_format = get_post_format($post->ID);
    								if ( $post_format == "" ) {
    									$post_format = 'standard';
    								}
    							?>
    							<li class="blog-item <?php echo $item_class; ?> format-<?php echo $post_format; ?>">
    								<?php echo sf_get_post_item($post->ID, $blog_type); ?>
    
    						<?php endwhile; ?>
    
    						<!-- CLOSE .blog-items -->
    
    					</div>
    
    				<?php else: ?>
    
    				<h3><?php _e("Sorry, there are no posts to display.", "swiftframework"); ?></h3>
    
    				<?php endif; ?>
    
    				<div class="pagination-wrap">
    					<?php echo pagenavi($wp_query); ?>
    				</div>
    
    			</div>
    
    			<aside class="sidebar left-sidebar span3">
    				<?php dynamic_sidebar($left_sidebar); ?>
    			</aside>
    
    		<?php } else { ?>
    
    		<div class="page-content clearfix">
    
    			<?php if(have_posts()) : ?>
    
    				<div class="blog-wrap">
    
    					<!-- OPEN .blog-items -->
    					<ul class="blog-items <?php echo $list_class; ?> clearfix">
    
    					<?php while (have_posts()) : the_post(); ?>
    
    						<?php
    							$post_format = get_post_format($post->ID);
    							if ( $post_format == "" ) {
    								$post_format = 'standard';
    							}
    						?>
    						<li class="blog-item <?php echo $item_class; ?> format-<?php echo $post_format; ?>">
    							<?php echo sf_get_post_item($post->ID, $blog_type); ?>
    
    					<?php endwhile; ?>
    
    					<!-- CLOSE .blog-items -->

    [Moderator Note: Please post code or markup between backticks or use the code button. Or better still - use a pastebin. Your posted code may now have been permanently damaged by the forum's parser.]

  16. Ajay
    Member
    Plugin Author

    Posted 6 months ago #

    Unfortunately not, it would be something like function sf_get_post_item( followed by other lines that you'll be able to find in one of the php files

    How comfortable are you editing files?
    Because, if you only want the related posts displayed, you should be able to ideally edit single.php

  17. ASBG
    Member
    Posted 6 months ago #

    From sf-post-formats.php

    public_html/wp-content/themes/flexform/includes/sf-content-display

    [Mangled code moderated. Please use a pastebin]]

  18. Ajay
    Member
    Plugin Author

    Posted 6 months ago #

    Could you please post this using http://pastebin.com/ and share the link. It ensures that the code doesn't get destroyed by the forum

  19. ASBG
    Member
    Posted 6 months ago #

  20. Ajay
    Member
    Plugin Author

    Posted 6 months ago #

    Hi checked out the code. There isn't any easy fix as far as I can see.

    You'll need to either remove the excerpt for this page, or alternatively do a manual install in your theme.

    Usage: <?php if(function_exists('echo_ald_crp')) echo_ald_crp(); ?> to your template file where you want the related posts to be displayed.
  21. ASBG
    Member
    Posted 6 months ago #

    Well I only want the related posts displayed on pages so could I instert

    <?php if(function_exists('echo_ald_crp')) echo_ald_crp(); ?>

    into the page template page.php file? if so where? the file looks like this

    <?php get_header(); ?>
    
    <?php
    	$options = get_option('sf_flexform_options');
    
    	$default_show_page_heading = $options['default_show_page_heading'];
    	$default_page_heading_bg_alt = $options['default_page_heading_bg_alt'];
    	$default_sidebar_config = $options['default_sidebar_config'];
    	$default_left_sidebar = $options['default_left_sidebar'];
    	$default_right_sidebar = $options['default_right_sidebar'];
    
    	$show_page_title = get_post_meta($post->ID, 'sf_page_title', true);
    	$page_title_one = get_post_meta($post->ID, 'sf_page_title_one', true);
    	$page_title_two = get_post_meta($post->ID, 'sf_page_title_two', true);
    	$page_title_bg = get_post_meta($post->ID, 'sf_page_title_bg', true);
    
    	if ($show_page_title == "") {
    		$show_page_title = $default_show_page_heading;
    	}
    	if ($page_title_bg == "") {
    		$page_title_bg = $default_page_heading_bg_alt;
    	}
    
    	$sidebar_config = get_post_meta($post->ID, 'sf_sidebar_config', true);
    	$left_sidebar = get_post_meta($post->ID, 'sf_left_sidebar', true);
    	$right_sidebar = get_post_meta($post->ID, 'sf_right_sidebar', true);
    
    	if ($sidebar_config == "") {
    		$sidebar_config = $default_sidebar_config;
    	}
    	if ($left_sidebar == "") {
    		$left_sidebar = $default_left_sidebar;
    	}
    	if ($right_sidebar == "") {
    		$right_sidebar = $default_right_sidebar;
    	}
    
    	$page_wrap_class = '';
    	if ($sidebar_config == "left-sidebar") {
    	$page_wrap_class = 'has-left-sidebar has-one-sidebar row';
    	} else if ($sidebar_config == "right-sidebar") {
    	$page_wrap_class = 'has-right-sidebar has-one-sidebar row';
    	} else if ($sidebar_config == "both-sidebars") {
    	$page_wrap_class = 'has-both-sidebars';
    	} else {
    	$page_wrap_class = 'has-no-sidebar';
    	}
    
    	$remove_breadcrumbs = get_post_meta($post->ID, 'sf_no_breadcrumbs', true);
    	$remove_bottom_spacing = get_post_meta($post->ID, 'sf_no_bottom_spacing', true);
    	$remove_top_spacing = get_post_meta($post->ID, 'sf_no_top_spacing', true);
    
    	if ($remove_bottom_spacing) {
    	$page_wrap_class .= ' no-bottom-spacing';
    	}
    	if ($remove_top_spacing) {
    	$page_wrap_class .= ' no-top-spacing';
    	}
    ?>
    
    <?php if (have_posts()) : the_post(); ?>
    
    <?php if ($show_page_title) { ?>
    	<div class="row">
    		<div class="page-heading span12 clearfix alt-bg <?php echo $page_title_bg; ?>">
    			<?php if ($page_title_one) { ?>
    			<h1><?php echo $page_title_one; ?></h1>
    			<?php } else { ?>
    			<h1><?php the_title(); ?></h1>
    			<?php } ?>
    			<?php if ($page_title_one) { ?>
    			<h3><?php echo $page_title_two; ?></h3>
    			<?php } ?>
    		</div>
    	</div>
    <?php } ?>
    
    <?php
    	// BREADCRUMBS
    	if(!$remove_breadcrumbs) {
    		echo sf_breadcrumbs();
    } ?>
    
    <div class="inner-page-wrap <?php echo $page_wrap_class; ?> clearfix">
    
    	<!-- OPEN page -->
    	<?php if (($sidebar_config == "left-sidebar") || ($sidebar_config == "right-sidebar")) { ?>
    	<div <?php post_class('clearfix span8'); ?> id="<?php the_ID(); ?>">
    	<?php } else if ($sidebar_config == "both-sidebars") { ?>
    	<div <?php post_class('clearfix row'); ?> id="<?php the_ID(); ?>">
    	<?php } else { ?>
    	<div <?php post_class('clearfix'); ?> id="<?php the_ID(); ?>">
    	<?php } ?>
    
    		<?php if ($sidebar_config == "both-sidebars") { ?>
    
    			<div class="page-content span6">
    				<?php the_content(); ?>
    			</div>
    
    			<aside class="sidebar left-sidebar span3">
    				<?php dynamic_sidebar($left_sidebar); ?>
    			</aside>
    
    		<?php } else { ?>
    
    		<div class="page-content clearfix">
    			<?php the_content(); ?>
    			<div class="link-pages"><?php wp_link_pages(); ?></div>
    <div class="share-links clearfix">
    						<div class="share-text"><?php _e("Share:", "swiftframework"); ?></div>
    						<div class="share-buttons">
    							<span class='st_facebook_hcount' displayText='Facebook'></span>
    							<span class='st_twitter_hcount' displayText='Tweet'></span>
    							<span class='st_googleplus_hcount' displayText='Google +'></span>
    							<span class='st_linkedin_hcount' displayText='LinkedIn'></span>
    							<span class='st_pinterest_hcount' displayText='Pinterest'></span>
    						</div>
    						<a class="permalink item-link" href="<?php the_permalink(); ?>"><i class="icon-link"></i></a>
    						<a class="email-link item-link" href="mailto:?subject=<?php the_title(); ?>&body=<?php the_permalink(); ?>" title="Share by Email"><i class="icon-envelope-alt"></i></a>
    					</div>
    
    		</div>
    
    		<?php } ?>
    <?php if ( comments_open() ) { ?>
    <div id="comment-area">
    	<?php comments_template('', true); ?>
    </div>
    <?php } ?>
    
    	<!-- CLOSE page -->
    	</div>
    
    	<?php if ($sidebar_config == "left-sidebar") { ?>
    
    		<aside class="sidebar left-sidebar span4">
    			<?php dynamic_sidebar($left_sidebar); ?>
    		</aside>
    
    	<?php } else if ($sidebar_config == "right-sidebar") { ?>
    
    		<aside class="sidebar right-sidebar span4">
    			<?php dynamic_sidebar($right_sidebar); ?>
    		</aside>
    
    	<?php } else if ($sidebar_config == "both-sidebars") { ?>
    
    		<aside class="sidebar right-sidebar span3">
    			<?php dynamic_sidebar($right_sidebar); ?>
    		</aside>
    
    	<?php } ?>
    
    </div>
    
    <?php endif; ?>
    
    <!--// WordPress Hook //-->
    <?php get_footer(); ?>
  22. ASBG
    Member
    Posted 6 months ago #

    Here is the pastbin for the page template page.php

    http://pastebin.com/fU3MD2Wt

  23. Ajay
    Member
    Plugin Author

    Posted 6 months ago #

    You can put it after:

    <?php the_content(); ?> which is line 98 and 108 of the pastebin

  24. ASBG
    Member
    Posted 6 months ago #

    That appears to have worked. I gather I will have to do that again any time I update the theme. Is there anything else I should bear in mind or settings I should change?

    Thanks for you time and help

  25. Ajay
    Member
    Plugin Author

    Posted 6 months ago #

    That's the only change you should ideally need to do to update the theme.

    You're welcome. If you do like the plugin, do consider giving a good review that will help other users (or potential users).

    https://wordpress.org/support/view/plugin-reviews/contextual-related-posts

  26. ASBG
    Member
    Posted 6 months ago #

    Problem, After doing that the exclude display of related posts on these posts / pages funcion no longer works. How to fix?

    Thanks

  27. Ajay
    Member
    Plugin Author

    Posted 6 months ago #

    You need to use code like this:

    <?php if ( ( function_exists('echo_ald_crp') ) && !is_single(array(17,15,20)) ) {
    echo_ald_crp();
    }
    ?>

    Change the 17,15,20 with the IDs of the post you want excluded.

  28. ASBG
    Member
    Posted 6 months ago #

    I put that over where I had

    <?php if(function_exists('echo_ald_crp')) echo_ald_crp(); ?>

    and related posts still show on all pages including the pages whose ID I entre.

    To be clear I an not wanting to nominate pages to not appear in the list of related post I want to nominate pages for related post not to display on.

  29. Ajay
    Member
    Plugin Author

    Posted 6 months ago #

    That's what the code I mentioned above should do. prevent display on pages whose ID's you enter

  30. ASBG
    Member
    Posted 6 months ago #

    Unfortunately it does not. related posts still displays on the page IDs that I enter.

Reply »

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.