Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8723199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:34:31+00:00 2026-06-13T07:34:31+00:00

this is the code that I use to create a submenu that list all

  • 0

this is the code that I use to create a submenu that list all custom post I create in wordpress:

    <ul class="submenu">
        <img src="<?php bloginfo('template_directory'); ?>/images/submenu.png" alt="submenu" width="62" height="1" />
        <!-- List post types -->
        <?php
            $the_query = new WP_Query( 'post_type=artworks_post' );
            // The Loop
            while ( $the_query->have_posts() ) : $the_query->the_post();
            echo '<li id="submenu_link" class="submenu_item_link">';
            echo '<a  href="' .get_permalink(). '" > ';
            the_title();
            echo '</a>';
            echo '</li>';
            endwhile;
            // Reset Post Data
            wp_reset_postdata();
        ?> 
        <img src="<?php bloginfo('template_directory'); ?>/images/submenu.png" alt="submenu" width="62" height="1" />
    </ul>

For example my current post is artworks_post/project-coke but it doesn´t add current/active class to the title of it in the submenu (Project Coke title).

How can I add an active/current class to the title of the current post in the submenu?

The submenu is constructed that way to get the custom post…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:34:32+00:00Added an answer on June 13, 2026 at 7:34 am

    Try my code ? :

    Put this code in your functions.php

    function if_current($s) {
        global $wp_query,$post;
        $current    = $wp_query->get_queried_object_id();
        $post_id    = $post->ID;
        if($current==$post_id){echo $s;}
    }
    

    So edit your code like :

    <ul class="submenu">
        <img src="<?php bloginfo('template_directory'); ?>/images/submenu.png" alt="submenu" width="62" height="1" />
        <!-- List post types -->
        <?php
            $the_query = new WP_Query( 'post_type=artworks_post' );
            // The Loop
            while ( $the_query->have_posts() ) : $the_query->the_post();
            echo '<li id="submenu_link" class="submenu_item_link ';
            if_current('current');
            echo '">';
            echo '<a  href="' .get_permalink(). '" > ';
            the_title();
            echo '</a>';
            echo '</li>';
            endwhile;
            // Reset Post Data
            wp_reset_postdata();
        ?> 
        <img src="<?php bloginfo('template_directory'); ?>/images/submenu.png" alt="submenu" width="62" height="1" />
    </ul>
    

    Result :

    <li id="submenu_link" class="submenu_item_link current">
    <a href="http://webkunst.comeze.com/test/artworks_post/project-coke/"> Project Coke</a>
    </li>
    

    PS: you can add whatever if_current('text') in loop in your theme, This will show when $post->ID == $wp_query->get_queried_object_id() (if current)

    So you can use class current in your CSS

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this JS code that I use to create a new div (I
I got this code that I use for User Create. public static void CreateUser(User
hello I have this code that use to sort a datatable. Dim sortingIndex As
this is the code that I use to disable the button $(#btnSubmit).attr('disabled', 'disabled') $(#btnSubmit).disabled
I have this code that where I would normally use one line: if (tableView
this is my code that I write it but I want to use LINQ
It was suggested that I use this line of code to call an image
In code: //I know that to get this effect (being able to use it
I'm attempting to use code I've found that uses Win32. However, I'm getting this
I have this code that runs but never stops. class A { public static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.