• benkhalil3

    (@benkhalil3)


    hi .. I would like to add this in the select menu options

    Custom links

    like this :

    
    1. You can use exact url, example: https://yoursite.com/post-name
    2. You can use page id. Example: 101
    3. You can use specific post name. Example: post-name
    4. To match an url part, you can use %{keyword}% example: %/en%

    it will be very helpfull espacially in big website which have more than 1000 pages .. so we can assign menu only by adding keyword

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author themifyme

    (@themifyme)

    Hi,

    Sorry, but I am not sure how that would work, eg. where the keyword is going to be added originally? and I am not sure if that would work with Conditional Menu if it is not a default WordPress query.

    rlohmj

    (@rlohmj)

    Hi @benkhalil3 & @themifyme,

    I’ve tried doing something similar with “keywords”, although its a bit more customized to suit my current requirements and not a general solution.

    In the solution I found, I could add a list of custom conditions (that include using keywords) to the “General” tab and the method is in the support thread, adding new custom conditional logic.

    Perhaps a working example is easier to understand than the initial gibberish I wrote while formulating my working code in the mentioned support thread. Pardon me if it is not optimized since I am not a good code writer.
    (In my working example, I made a set of custom conditions to switch menus depending on the ASEAN country at the start of the URL Path such that https://example.com/brunei/* will display the conditional menu with “Brunei” checkbox checked, https://example.com/laos/* will display the conditional menu with “Laos” checkbox checked, etc.)

    There are 3 steps, the last step is optional:

    1. Display my custom conditions checkboxes in the “General” tab:
    In public function get_visibility_options( $selected = array() ) {,
    I added my custom conditions checkboxes in /* build the tab items */ like this:

    /* build the tab items */
    $output .= '<div id="visibility-tab-general" class="themify-visibility-options clearfix">';
    	/*customconditionsstart*/
    	$customcondscountries = array('brunei','cambodia','indonesia','laos','malaysia','myanmar','philippines','singapore','thailand','vietnam');
    	foreach ($customcondscountries as $customcondscountry) {
    		$checked = isset( $selected['general'][$customcondscountry] ) ? checked( $selected['general'][$customcondscountry], 'on', false ) : '';
    		$output .= '<label><input type="checkbox" name="general['.$customcondscountry.']" '. $checked .' />' . __( ucfirst($customcondscountry), 'themify-cm' ) . '</label>';
    	}
    	/*customconditionsend*/
        ... ...

    2. Check if new custom conditions returns “true” or “false”:
    In public function check_visibility( $logic ) {,
    I added in my custom conditions in the first if (!empty($logic)) { like this:

    if (!empty($logic)) {
        /*customConditionsStart*/
        $customcondscountries = array('brunei', 'cambodia', 'china', 'india', 'indonesia', 'laos', 'malaysia', 'myanmar', 'philippines', 'singapore', 'thailand', 'vietnam');
        foreach ($customcondscountries as $customcondscountry) {
            if (isset($logic['general'][$customcondscountry]) && (strtok(parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH), "/") == $customcondscountry)) {
                return true;
            }
        }
        /*customConditionsEnd*/
        ... ...

    3. (Optional) Rename “General” tab to “Custom and General” tab:
    In public function get_visibility_options( $selected = array() ) {,
    I renamed the “General” tab in

    /* build the tab links */
    		$output .= '<li><a href="#visibility-tab-general">' . __( 'General', 'themify-cm' ) . '</a></li>';

    like this:

    /* build the tab links */
    		$output .= '<li><a href="#visibility-tab-general">' . __( 'Custom and General', 'themify-cm' ) . '</a></li>';
    • This reply was modified 3 years ago by rlohmj. Reason: fix incorrect display of apostrophes and double apostrophes
    Plugin Author themifyme

    (@themifyme)

    Hi,

    Unfortunately we don’t have that exact function, but we do have something similar, like the “Auto-apply sub-pages’ which will apply the same condition for all sub-pages of the page you select or In Category, so if you select a Category from the “In Category” Condition it will apply to all posts from that selected Category, unfortunately the exact thing with the URL selector we don’t have, but you can do customize the plugin with your own code if you need that custom function.

    rlohmj

    (@rlohmj)

    Hi @themifyme,

    Unfortunately, the “Auto-apply sub-pages” feature is glitchy.

    Example:

    There are these pages in a website, 1 homepage, 2 parent “sub-dir”, 2 child “sub-page” per parent “sub-dir”.

    • home
    • sub-dir-1
    1. sub-page-1
    2. sub-page-2
    • sub-dir-2
    1. sub-page-1
    2. sub-page-2

    In the Page Builder Framework theme, the “Auto-apply sub-pages” feature works in the “main menu” location and does not work in the “mobile menu” location. (I did not need the 2 footer locations and did not test them.)

    Additionally, for unknown reasons, even though the parent page selected is “sub-dir-1”, child pages “sub-page-1” and “sub-page-2” under parent page “sub-dir-2” gets selected as well in the “main menu” location.
    Based on what I understand from the source code (which I may be wrong), the child pages are selected based on their page slug. Since the page slug for the child pages “sub-page-1” and “sub-page-2” under parent page “sub-dir-2” are the same as the child pages “sub-page-1” and “sub-page-2” under parent page “sub-dir-1”, they get selected as well. (I did not need deeper levels of child pages and did not test them.)

    • This reply was modified 3 years ago by rlohmj. Reason: rectify incorrect unordered and ordered list format
    Thread Starter benkhalil3

    (@benkhalil3)

    @themifyme
    @rlohmj

    There is a similar plugin : different menu in different pages which has this feature of custom links and fields ..but it is limited to only 6 menues . I wondering if you can do the same thing for you plugin.

    please see this image to understand me where you can put this feature. It will be very helpful

    View post on imgur.com

    rlohmj

    (@rlohmj)

    Hi @benkhalil3,

    I knew of Different Menu in Different Pages – Control Menu Visibility By ReCorp and if you wanted that feature of theirs and with unlimited menus, they have the paid version and their efforts to develop it should be supported.

    That said, if you really want a free alternative immediately, needed more than 6 menus, use regex keywords and do not mind writing some codes (and know what you are doing with PHP), you could make use of “preg_quote” and “preg_match” to create regex conditions for the URL and modify Conditional Menus source code as I described above.
    I found this page useful in finding out “How To Get Full URL & URL Parts In PHP”.

    I have personally tried to recreate that exact feature in Conditional Menus and only succeeded visually in the admin screen. I could not get the plugin to check against the regex string in the created input field in the public function check_visibility( $logic ) and no menu with regex condition was displayed in the website’s front end. I also faced the problem of storing different regex string conditions across different menus with conditions.

    Hence as a Disclaimer, Please test your modified plugin with a “clone” or “staging” wordpress install so your original website remains unaffected in the event of dissatisfying results.

    Lastly, who doesn’t like free and fantastic plugins!
    @themifyme, making use of regex conditions for the URL is a good suggestion to include in your plugin and I recommend it too.

    Plugin Author themifyme

    (@themifyme)

    Hi @rlohmj

    Yes, our “Auto-apply sub-pages” works like that, so it only works for the sub-pages ( Child Pages ). I will ask our lead developer to check if we can implement this feature ( Custom Links ) in our plugin.

    • This reply was modified 3 years ago by themifyme.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom links and keywords’ is closed to new replies.