Forums

Can I insert php code into my menu?? (6 posts)

  1. Erve1879
    Member
    Posted 10 months ago #

    I'm trying to find a way of adding a piece of php code into my menu.

    I'm trying to use this code:

    <?php echo get_category_by_slug('news')->category_count; ?>

    to add a number-of-posts-in-category count to my menu. The idea is that the categories in my menu (eg. NEWS) will show the number of posts in that category ie "NEWS (76)".

    I've tried adding the above code into the custom menu navigation label, but it just displays the code in raw form in the menu.

    Is there any way to achieve what I am trying to do???

    Thanks very much!!

  2. jjvasquez
    Member
    Posted 10 months ago #

    try, if you know the category id

    $cats = get_categories('include=4','hide_empty=1');
    echo "<h1> count is ".$cats[0]->count."</h1>";

  3. Erve1879
    Member
    Posted 10 months ago #

    Thanks jjvasquez - where do I insert the category id?

  4. Erve1879
    Member
    Posted 10 months ago #

    I've tried inserting the code into the menu (in the Navigation Label box), but it just shows the raw code in the menu.....

  5. Erve1879
    Member
    Posted 10 months ago #

    Does anyone else have any ideas??

  6. Erve1879
    Member
    Posted 10 months ago #

    I would really love some help!!

Reply

You must log in to post.

About this Topic