Fetch Category Articles Programatically

This support request was posted in Flatbase by azhararmar

Request ID #31095 Resolved
  • Hi,

    We are developing a website for our client who has purchased your theme flatbase, one of the feature we are working on is to display the list of all categories and all articles of the category in a pop-up using hamburger approach in single-article page, FYI you can check this in the following URL http://dgtesk.oroserver1.com/article/card-field-editor/ click on the hamburger icon below the title and in nice-theme menu.

    As you’ll see, we are displaying the list of categories, what I now want is to also display the list of all articles when a category is selected, for this I added following code in single-article.php (of-course in child theme)

    	<?php nice_breadcrumbs( array( 'singular_article_taxonomy' => 'article-category' ) ); ?>
    	<h1 class="entry-title"><?php the_title(); ?></h1>
    	<a href="#" class="accordion-toggle-btn">
    		<i class="fa fa-bars" aria-hidden="true"></i>
    	<ul class="accordion-menu">
    			$cat_args = array(
    				'taxonomy' 		=> 'article-category',
    				'orderby'		=> 'menu_order',
    				'order' 		=> 'ASC',
    				'hierarchical' 	=> true,
    				'parent' 		=> 0,
    				'hide_empty' 	=> true,
    				'child_of' 		=> 0
    			$categories = get_categories( $cat_args );
    		<?php foreach ($categories as $category): ?>
    				<a href="#"><?php echo $category->name; ?></a>
    				<?php $cats = get_categories(); foreach ( $cats as $cat ) { query_posts( 'cat=' . $cat->cat_ID ); } ?>
    				<ul class="accordion-menu-sub">
    					<?php while (have_posts()) : the_post(); ?>
    						<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
    					<?php endwhile;  ?>
    		<?php endforeach; ?>
    	<?php nice_article_meta(); ?>

    The issue is, it does not fetch the related articles of the category, can you please help, I am kind of stuck here on how to go about it.


    Hi, any update on this?

    Juanfra Aldasoro


    Thank you for writing. I hope you are doing well.

    When I follow your link I only see a page with some IDs. Unfortunately we cannot give support on customizations. We have written a detailed article about the scope of our support: https://nicethemes.com/article/support-vs-customizations-2/

    Regarding the way the articles are queried, you can check the function nicethemes_knowledgebase() in the file /includes/functions.php – that way you will have an idea on how categories and articles are queried, and perhaps it will give you a solution.

    The theme also has a function to display related posts/articles. The function is named nice_related_posts() and it can be found in /includes/template-tags.php.


    Nevermind, I solved the issue.


    Juanfra Aldasoro

    Thank you for the follow-up.

    That’s great news 🙂

    I hope you have a nice day.


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

This topic is marked as resolved

Only the topic author can re-open this thread.

Login to your Account

Welcome back! Please log in to your account by filling the fields below:


Not a member? Create a free account.

Create a Free Account

You're 27 seconds away from some awesome WordPress free stuff, benefits and more. Create a free account and have access to our free products, benefits and more!

Already have an account? Log in
Secure Server