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)

    <header>
    	<?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>
    	</a>
    	<ul class="accordion-menu">
    		<?php
    			$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): ?>
    			<li>
    				<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;  ?>
    				</ul>
    			</li>
    		<?php endforeach; ?>
    	</ul>
    	<?php nice_article_meta(); ?>
    </header>

    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.

    Thanks.

    Hi, any update on this?

    Juanfra Aldasoro

    Hi,

    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.

    Best,
    Juan.

    Nevermind, I solved the issue.

    Thanks.

    Juanfra Aldasoro

    Thank you for the follow-up.

    That’s great news 🙂

    I hope you have a nice day.

    Best,
    Juan.

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:

Forgot?

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