Thank you! Your feedback has been delivered
Thank you! Your feedback has been sent

Tiny WordPress Code.

Hi there,

We have a WordPress site with this structure:

Book Category:

  • Book A

--Section A1

--Section A2

----Post A2-1

----Post A2-2

--Section A3

  • Book B
  • Book C
  • Book D

While we are on ----Post A2-1 (and only on internal posts) we want a code to show other sections of the book on the Sidebar

Like Section A1 Section A2

So only on single posts, we need to show other sections of the book (and not internal posts).

Any help would be appreciated.

Bests, Danial

User Gravatar

daanial

Posted Jun 28 2014 3:31 UTC

$25


  • Assigned To Dearon
  • Solved
  • php
    wordpress
  • 498 Views

5 Replies


P.s: Actually the site is not in English so adding the URL won't be helpful. And the current code is:

<div class="rightSide"  id="rightSideDiv">
<img class="logo" alt="Mohsen Kadivar" src="<?php bloginfo('template_directory')?>/images/logo.gif" />




<div class="right-sidebar">



<?php if (  is_single() && is_active_sidebar( 'secondary-widget-area' ) ) : ?>

    <p>This is the menu</p>


<ul> 
<?php wp_list_categories('orderby=id&show_count=1&use_desc_for_title=0'); ?>
</ul>

                <?php // dynamic_sidebar( 'secondary-widget-area' ); ?>
<?php endif; ?>


</div>  

    </div>
User Gravatar

daanial

Posted Jun 28 2014 3:42 UTC

They are just simple posts with three levles of category / Subcategory

Once again like this:

x Category Books

xx Category Book A

xxx Category Section A1

xxxx Post of sections A1

In the sidebar of these posts, I would like to show all (sub)categories of the same sub category this post belongs to:

Like

"xxx sections A1" "xxx sections A2" "xxx sections A3"

and...

User Gravatar

daanial

Posted Jun 28 2014 3:54 UTC

<?php
    $category = get_the_category();
    $parent_category = $category[0]->category_parent;

    $args = array(
        'orderby' => 'id',
        'show_count' => '1',
        'use_desc_for_title' => 0,
        'child_of' => $parent_category
    );

    wp_list_categories($args);
?>

If I understand you correctly this that should do what you want

User Gravatar

Dearon

Posted Jun 28 2014 4:05 UTC

Solution

This didn't solve your task? Get your own custom solution.

Great. Simple! :)

User Gravatar

daanial

Posted Jun 28 2014 4:24 UTC

Awesome, happy to hear it helped

User Gravatar

Dearon

Posted Jun 28 2014 4:30 UTC

Add a reply

By posting a reply on CodersClan you agree to our Terms & Conditions