Forum Replies Created

Viewing 15 replies - 1 through 15 (of 27 total)
  • TLDR; So basically I copied your example listed here: https://gist.github.com/ajaydsouza/968b24a052e858bf8926 and just modified the code where in $scores array with ‘postid’ assigning to value of $ajaxPost->ID and it works πŸ™‚ The posts are now fetched and displayed πŸ˜€

    Ok so I found that:

    • $post_id was returning ID as a string.
    • $ajaxPost->ID was returning ID as an integer.
    • If I var_dump $ajaxPost I get a successful WP_Post object with all correctly inserted post data. β€œID” being the integer of 7857 for example. So the ID was being fetched correctly.

    Then I tried: var_dump( get_crp_posts_id( $ajaxPost->ID) ); but it returned bool(false).

    But if I do: var_dump( get_crp_posts_id(array( 'postid '=> $ajaxPost->ID ) ); it returns succesfully the array(4) of four related posts (their data wrapped in Objects) and their respective ID’s.

    So basically I copied your example listed here: https://gist.github.com/ajaydsouza/968b24a052e858bf8926 and just modified the code where in $scores array with ‘postid’ assigning to value of $ajaxPost->ID and it works πŸ™‚ The posts are now fetched and displayed πŸ˜€

    The full code regarding working related posts is now like this:

    if ( function_exists( 'get_crp_posts_id' ) ) {
    		$scores = get_crp_posts_id( array(
    			'postid' => $ajaxPost->ID,
    			'limit' => 4 
    		) );
    		$posts = wp_list_pluck( (array) $scores, 'ID' );
    		$args = array(
    			'post__in' => $posts,
    			'posts_per_page' => 4,
    			'ignore_sticky_posts' => 1 
    		);
    		$my_query = new WP_Query( $args );
    		if ( $my_query->have_posts() ) {
    			echo '<ul>';			
    			while ( $my_query->have_posts() ) {
    				$my_query->the_post();
    				echo '<li>';
    				echo '<a href="' . get_permalink( get_the_ID() ) . '">';
    				echo '<img src="' . get_the_post_thumbnail_url() . '" />';
    				the_title();
    				echo '</a>';
    				echo '</li>';
    				wp_reset_postdata();
    			}
    			echo '</ul>';
    		} else {
    		}
    		wp_reset_query();
    	}
    
    		wp_reset_postdata();
     
    	die();

    Thanks for your support & I’ll make sure this plugin gets 5 star rating from me πŸ™‚

    • This reply was modified 1 year, 3 months ago by jeroslav. Reason: Reply marked as resolved

    OK, just checked the plugin settings again. I had “When there are no posts, what should be shown?” checked to blank output. Now I’ve set it to “No related posts found” and it displays this text.

    So actually it doesn’t find related posts via AJAX functionallity.. Because I have single.php file that loads without AJAX (for example if the user goes directly to some specific post by inserting the post URL in the browser the related posts are displayed).

    So this “No related posts found” happens only when the new post is loaded dynamically with AJAX. So without single.php page “interaction” in this case.

    Yup, just tried it. The result is the same, it outputs just the empty div with id=”crp_related”.

    I also did the var_dump(get_crp( $post_id)); and I got string(29) and then <div id="crp_related"> </div>. Which is this string with 29 characters. But nothing inside it.

    function cy_getContent_function(){
    
    	$post_id = $_POST['postContent'];
    	$post_author = get_post_field( 'post_author', $post_id );
    	
    	setPostViews($post_id);	
    
    	if( isset( $post_id ) ) {
    		$ajaxPost = get_post($post_id);
    	} else {
    		$args = array(
    			'orderby' => 'date', // we will sort posts by date
    			'order'	=> $_POST['date'] // ASC ΠΈΠ»ΠΈ DESC
    		);
    	}
    	
    
    		echo '<div class="news-content-byline">';
    		echo get_the_post_thumbnail($post_id);
    		echo '<span>' . get_the_author_meta('display_name', $post_author) .'</span>';
    		echo '<span class="close-news-content"><i class="fa fa-close"></i></span>';		
    		echo '<span class="date-published">Published on: ' . date('F j, Y', strtotime($ajaxPost->post_date)) . '</span>';
    		echo '</div>';
    		echo '<div class="news-content-content">';
    		echo '<h2>' . $ajaxPost->post_title . '</h2>';
    		echo '<p>' . $ajaxPost->post_content . '</p>';
    		echo '<a href="' . get_post_meta($post_id, 'wprss_item_permalink', true) .'" id="read-more" target="_blank">READ FULL ARTICLE</a>';
    		
    		
    		echo do_shortcode('[crp limit="5" heading="1" cache="0"]');
    		if ( function_exists( 'echo_ald_crp' ) ) echo_ald_crp(); 
    
    		wp_reset_postdata();
     
    	die();
    }

    This is the function that returns an AJAX response, I use it in the functions.php file.

    Should I be calling any JS function, for example new init or something? Or is it because the function is not used inside the loop and I am fetching the posts data by posts ID. Should I be passing the post ID? πŸ™‚

    • This reply was modified 1 year, 3 months ago by jeroslav.
    • This reply was modified 1 year, 3 months ago by jeroslav.

    Ok thank you for your reply. I will check if it works on the default theme and do the plugins conflict test.

    Is there a way to load a <link></link> element from the RSS Feed that is inside the <channel>element.

    So that, I could display the source’S URL like: https://www.cnn.com, or if there is a way to display just the source name: CNN. I know this could be done by author name and such, but I would like to know if there is any other way, or if I could make a WP_Query to the database to pull out such information.

    Thank you.

    • This reply was modified 1 year, 5 months ago by jeroslav.
    • This reply was modified 1 year, 5 months ago by jeroslav.

    Ok the page.php file was missing.. Its working now πŸ˜€

    I got it all working.. Go over all of this, I hope it helps.

    http://codex.wordpress.org/Theme_Development#Plugin_API_Hooks

    Make sure you have all the php functions in order as specified in documentation. I assume you are working on your own theme.

    I am having the same problem.. I hope someone will help.

    In my case the problem was that I forgot to include <!DOCTYPE HTML> at the beginning of HTML document. Now I learned it to ALWAYS INCLUDE HTML DECLARATION πŸ˜€

    The problem was that I didnt included <!DOCTYPE HTML> declaration at the beginning of HTML document!

    Yep, I am having the same problem too. I guess there is something wrong with positioning in CSS files…

    jeroslav

    (@jeroslav)

    Ravinder Kumar: Thank you for the WP_query reference, it sure is a must read!

    alchymyth: Yes its about replicating my HTML structure, but with some changes in CSS.

    I am working on my own theme, and its located on localhost, so I cant post any links here.

    I managed to solve it anyway. I think there are more ways how to solve it.
    I created a new category in Administration panel for this specific page. Then I added this code

    <?php $page_query = new WP_Query('post_type=post&category_name=predpisi'); ?>
    		<?php while ($page_query->have_posts()) : $page_query->the_post(); ?>

    With category_name= /* chosen category name for that specific page */

    After that I excluded to show the posts by the same category on index.php with this:

    <?php
    if ( is_home() ) {
    query_posts( ‘cat=-32’ );
    }
    ?>

    32 is ID of the category we dont want to display on the page.
    – excludes the category.

    That is one possible way to solve this and it works fine for me. Anyway thanks for your time πŸ™‚

    Ok now it works!

    with this:

    <img src="<?php echo bloginfo('template_directory') . '/img/sample/family.jpg'; ?>" alt="smiling girl" class="thumb"/>

    its template_directory instead of get_template πŸ˜€

    anyway thanks for your time Andrew! πŸ™‚

    Hmmm, when i use

    <img src="<?php echo bloginfo('get_template') . '/img/sample/family.jpg'; ?>" alt="smiling girl" class="thumb"/>

    its the URL

    <img src="ZPMpravna/img/sample/family.jpg" alt="smiling girl" class="thumb"/>

    but the index.php file is located in ZPMpravna so isnt that the URL should be “/img/sample/family.jpg” without the ZPMpravna?

    Yep I still get it.

Viewing 15 replies - 1 through 15 (of 27 total)