Home Forums WoodMart support forum Related Blog Post Same Category

Related Blog Post Same Category

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #212769

    luan0409
    Participant

    I want to change Related Blog Post Same Tags to Same Category

    I’ve read some topics here

    You mention that I need to create a template and put it below the content. But the thing for me is I don’t want to put the Related Posts just below the content but BELOW THE COMMENT SECTION.

    That’s why I need to change the code so I can move it around where I want instead of just creating a template and it stuck just within the content.

    I have searched online for some code too and try to put them inside SINGLE.PHP but it just breaks the theme

    So pls give me some code to change from Same Tags to Same Category just inside SINGLE.php or wherever place it should be.

    I have about a thousand Blog Posts to write so I can’t just manually put tags to every post all the time. I will forget them somehow, someway so I really need to get this fix

    Thanks.

    #212800

    Artem Temos
    Keymaster

    Hi,

    Try to add the following PHP code snippet to the child theme functions.php file to do this

    function woodmart_get_related_posts_args( $post_id ) {
    		$cats = get_the_category();
    		$args = array();
    		if ( $cats ) {
    			$args = array(
    				'cat'               => $cats[0]->term_id,
    				'post__not_in'          => array( $post_id ),
    				'showposts'             => 12,
    				'ignore_sticky_posts'   => 1
    			);
    		}
    		return $args;
    	}

    Regards

    #533325

    Mric
    Participant

    Hello,
    I want to do same thing, I tried with your code, but it’s not ok.
    Does you have an other code for this function ?
    thanks.

    #533326

    Mric
    Participant

    Sorry : code is OK 🙂

    Thanks

Viewing 4 posts - 1 through 4 (of 4 total)