rlohmj
Forum Replies Created
-
Thank you for the workaround.
I have informed my colleagues to do the rollback.
Upon further inspection of the submitted form data, I notice that the “default values” issue may be more serious than I initially thought.
Default values for “input” type form fields are also not captured by the form, just like the “number” type form fields.
I did not do any further inspections with regards to default values (for my other “radio” type form fields), but I suspect that the default values are not populating as they should across most, if not all, form field types available to us and should be looked into quickly.
Exported form with fake email in “email notification”:
https://pastebin.com/3jNF24t7Unfortunately, the form is used on an internal site and I am not allowed to disclose it.
If a “live” form is required, I can put in a request to make a separate example site, but I doubt it will get approved.
Thank you.
Hi @peterschulznl,
Connecting without SSL works perfectly.
I’m using a provider, so I’ve informed them of my issue and its resolved.
Thank you for the clarification!
Forum: Plugins
In reply to: [Conditional Menus] Custom links and keywordsHi @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.Forum: Plugins
In reply to: [Conditional Menus] Custom links and keywordsHi @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
- sub-page-1
- sub-page-2
- sub-dir-2
- sub-page-1
- 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 4 years, 1 month ago by rlohmj. Reason: rectify incorrect unordered and ordered list format
Forum: Plugins
In reply to: [Conditional Menus] Custom links and keywordsHi @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:
Inpublic 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”:
Inpublic function check_visibility( $logic ) {,
I added in my custom conditions in the firstif (!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:
Inpublic 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 4 years, 1 month ago by rlohmj. Reason: fix incorrect display of apostrophes and double apostrophes
Forum: Plugins
In reply to: [Conditional Menus] adding new custom conditional logicHi @themifyme,
I was reading up on how I could add the custom function to add new conditions for the menus and realized that:
- The plugin does not have a “apply_filters()” function for developers to include their own conditions without “touching” the source code of this plugin.
- Hence, using the “add_filter()” function example I suggested cannot be used to append or prepend new conditions since the prerequisite “apply_filters()” call is not present.
Looking at similar types of plugins to add conditions for menu visibility or swapping, I found If Menu – Visibility control for Menu Items that allows adding custom conditions. That plugin only hides the menu element rather that swapping the entire menu.
For my needs, Conditional Menus is fantastic in the sense that entire menus can be swapped for a range of specific pages.
However I also require a second condition for the URL path to start with a specific word, example “windmill” in “https://example.com/windmill/gristmill”.The source code modification I mentioned in the thread starter adds the second condition perfectly.
I suggest including an appropriate “apply_filters()” call in this plugin to boost the plugin’s functionality greatly by allowing others to include their own custom conditions and make the plugin update friendly. The added “apply_filters()” call would most likely help put this plugin ahead of most rival plugins in this category.
Edit:
I’m not sure why, but all the example weblinks end with “”” although I did not type that. Please ignore the “””.- This reply was modified 4 years, 1 month ago by rlohmj. Reason: Clarify "”" at end of weblinks
Forum: Plugins
In reply to: [Conditional Menus] adding new custom conditional logicHi @themifyme,
I was asking if there is a way to add new conditions via a function rather than directly modifying the source “init.php” file of the plugin.
Notice how additional lines of code were inserted into the existing code inside the “init.php” file as seen in the initial message.
The method mentioned in the initial message is not plugin update friendly and I am asking how I can make adding new conditions update friendly.
Hi Peter,
Thanks for the clarification.
I’ve tested my updated code and it works great!
Hi Peter,
Just to clarify any remaining doubts I have …
That means I need to call
$wpdadb = WPDataAccess\Connection\WPDADB::get_db_connection( 'your-local-db-name' );
rather than the usual
global $wpdb;
before this set of revised (replaced $wpdb with $wpdadb) codes$param1 = $wpdadb->esc_like($wpda_shortcode_args['param1']); $param2 = '%0' . $wpdadb->esc_like($wpda_shortcode_args['param2']) . '0%'; $my_result = $wpdadb->get_results( $wpdadb->prepare( "SELECT * FROM my_table WHERE my_col2 LIKE %s AND my_col3 LIKE %s ORDER BY my_col2 ASC", $param1, $param2 ) );and “your-local-db-name” is what is seen in the “Database” text field in your plugin screenshot here: WP Data Access plugin sample screenshot on wp.
Because my db is local rather than remote, it would be something like “dfg_d68fd” rather than “rdb:dfg_d68fd”.
Hi @peterschulznl ,
I’m liking your plugins more and more as I use them! 🙂
I completed the hardcoded version for the sample pics and merged them into a single snippet.
Some custom parameters are needed to work, namely “country”, “service”, “port”, “rotloc” (slideshow rotation location).
I manage to separate the sevices/ports in the sample example by putting “0”s before and after each phrase in the database such that the custom parameters for “service”/”port” = “0?? ??-??0” work very well since numbers are not commonly used to label the service or port.Full PHP code to display the data as per the sample images here:
<?php global $wpda_shortcode_args; if (isset($wpda_shortcode_args['country']) && isset($wpda_shortcode_args['rotloc'])) { global $wpdb; $wpdb->flush(); unset($result); $sitecountry = $wpdb->esc_like($wpda_shortcode_args['country']); $rotloc = $wpdb->esc_like($wpda_shortcode_args['rotloc']); $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM rotatingads WHERE rotads_country LIKE %s AND rotads_loc LIKE %s ORDER BY rotads_set ASC", $sitecountry, // an unescaped string (function will do the sanitization for you) $rotloc, // an unescaped string (function will do the sanitization for you) ) ); switch ($wpda_shortcode_args['rotloc']) { case 'sidebar': echo '<style> /* Style Sidebar */ #featuredSideBar>div { box-sizing: border-box; width: 100%; margin-bottom: 5px; } #featuredSideBar>div:last-child { margin-bottom: 0px; } </style>'; echo '<div id="featuredSideBar">'; $slide = 0; echo '<div class="slideSet">'; foreach ($result as $row) { if ($slide != $row->rotads_set && $slide != 0) { $slide += 1; echo '</div>'; echo '<div class="slideSet">'; } elseif ($slide == 0) { $slide += 1; } if (substr($row->rotads_link, 0, 4) == 'tel:' || substr($row->rotads_link, 0, 7) == 'mailto:') { echo '<a rel="noopener nofollow" href="' . $row->rotads_link . '" style="text-decoration: none;">'; } else { echo '<a rel="noopener nofollow" target="_blank" href="' . $row->rotads_link . '" style="text-decoration: none;">'; } echo '<img loading="lazy" src="' . $row->rotads_imgsrc . '" alt="' . $row->rotads_desc . '" style="width: 100%; height: auto;">'; echo '</a>'; } echo '</div>'; echo '</div>'; echo '<script> var SlideIndex = []; var SlideSet = []; for (var setnum = 0; setnum < jQuery("#featuredSideBar .slideSet").length; setnum++) { SlideIndex[setnum] = 0; SlideSet[setnum] = jQuery("#featuredSideBar .slideSet:eq(" + setnum + ") > a"); } SlideMaker(); function SlideMaker() { for (var setnum = 0; setnum < jQuery("#featuredSideBar .slideSet").length; setnum++) { SlideIndex[setnum] = ShowSlides(SlideSet[setnum], SlideIndex[setnum] += 1); } setTimeout(function() { SlideMaker(); }, 2000); }; function ShowSlides(s, n, t) { if (n > s.length) { n = 1; } if (n < 1) { n = s.length; } for (var i = 0; i < s.length; i++) { s[i].style.display = "none"; if (t != null) { t[i].classList.remove("activeThumbDot"); } } s[n - 1].style.display = "block"; if (t != null) { t[n - 1].classList.add("activeThumbDot"); } return n; }; </script>'; break; case 'body': echo '<style> /* Position the image container (needed to position the left and right arrows) */ #featuredBody { position: relative; } /* Next & previous buttons */ #featuredBody .prev, #featuredBody .next { cursor: pointer; position: absolute; top: 0; width: auto; padding: 5px 10px; margin-top: -27px; color: rgba(0, 0, 0, 0.5); background-color: rgba(255, 255, 255, 0.3); font-weight: bold; font-size: 10px; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; -webkit-user-select: none; -ms-user-select: none; -moz-user-select: none; -o-user-select: none; user-select: none; } /* Position the "next button" to the right */ #featuredBody .next { right: 0; } /* On hover, add a black background color with a little bit see-through */ #featuredBody .prev:hover, #featuredBody .next:hover { color: white; background-color: rgba(0, 0, 0, 0.8); } /* Add a pointer when hovering over the thumbnail images */ .cursor { cursor: pointer; } /* The dots/bullets/indicators */ .thumbDot { cursor: pointer; height: 11px; width: 11px; margin: 7px 2px; background-color: #bbb; border-radius: 50%; display: inline-block; } .activeThumbDot, .thumbDot:hover { background-color: #717171; } </style>'; echo '<div id="featuredBodyMiniPics" style="text-align:center; margin: 0; padding: 0; line-height: 0.5;">'; for ($i = 1; $i <= $wpdb->num_rows; $i++) { echo '<span class="thumbDot" onclick="CurrentSlide(' . $i . ')"></span>'; } echo '</div>'; echo '<div id="featuredBody" style="width: 100%; margin: 0 auto; padding: 0;">'; echo '<div class="slideSet">'; foreach ($result as $row) { echo '<a rel="noopener nofollow" target="_blank" href="' . $row->rotads_link . '" style="text-decoration: none;">'; echo '<img loading="lazy" src="' . $row->rotads_imgsrc . '" alt="' . $row->rotads_desc . '" style="width: 100%; height: auto;">'; echo '</a>'; } echo '</div>'; echo '<a class="prev" onclick="PlusSlides(-1)">❮</a>'; echo '<a class="next" onclick="PlusSlides(1)">❯</a>'; echo '</div>'; echo '<script> var slideTimeout; var thumbs = document.getElementById("featuredBodyMiniPics").getElementsByClassName("thumbDot"); var bodyslides = document.getElementById("featuredBody").getElementsByClassName("slideSet")[0].getElementsByTagName("A"); var slideIndex = Math.floor(Math.random() * bodyslides.length); function SlideActive() { slideIndex = ShowSlides(bodyslides, slideIndex += 1, thumbs); slideTimeout = setTimeout(function() { SlideActive(); }, 2000); }; function PlusSlides(n) { clearTimeout(slideTimeout); slideIndex = ShowSlides(bodyslides, slideIndex += n, thumbs); slideTimeout = setTimeout(function() { SlideActive(); }, 5000); }; function CurrentSlide(n) { clearTimeout(slideTimeout); slideIndex = ShowSlides(bodyslides, n, thumbs); slideTimeout = setTimeout(function() { SlideActive(); }, 5000); }; SlideActive(); </script>'; break; default: break; } } elseif (isset($wpda_shortcode_args['country']) && isset($wpda_shortcode_args['service'])) { global $wpdb; $wpdb->flush(); unset($result); $sitecountry = $wpdb->esc_like($wpda_shortcode_args['country']); $portservice = '%' . $wpdb->esc_like($wpda_shortcode_args['service']) . '%'; $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM company WHERE company_services_ads_approval = %d AND company_country LIKE %s AND company_services_list LIKE %s ORDER BY company_services_ads_type ASC, company_name DESC", 1, // an untrusted integer (function will do the sanitization for you) $sitecountry, // an unescaped string (function will do the sanitization for you) $portservice, // an unescaped string (function will do the sanitization for you) ) ); echo '<div id="listings" class="notranslate">'; foreach ($result as $row) { echo '<p style="margin: 0px;">'; if ($row->company_services_ads_type == 'banner') { echo '<a href="#Top" rel="noopener nofollow" style="font-size: 12px; line-height: 1;" onclick="showListing(this)" data-imgsrc="' . $row->company_services_ads_imgsrc . '" data-imglink="' . $row->company_services_ads_link . '">'; echo '<strong style="font-size: 14px;">' . $row->company_name . '</strong>'; } else { echo '<a href="#Top" rel="noopener nofollow" style="font-size: 12px; line-height: 1;" onclick="showListing(this)" data-list="<br>' . $row->company_address . '<br>' . $row->company_phone . '<br>' . $row->company_email . '<br>' . $row->company_website . '">'; echo $row->company_name; } echo '</a>'; echo '</p>'; } echo '</div>'; echo '<script> function showListing(elem) { if (elem.hasAttribute("data-list")) { document.getElementById("listingInfo").innerHTML = ""; elem.infoDiv = document.createElement("DIV"); elem.infoDiv.style.padding = "0.5em"; elem.infoDiv.style.fontSize = "12px"; elem.infoDiv.style.lineHeight = "1"; elem.infoDiv.style.border = "solid 1px black"; elem.infoDiv.innerHTML = elem.innerHTML + elem.getAttribute("data-list").replace(/(\<br\>-)/g, ""); document.getElementById("listingInfo").appendChild(elem.infoDiv); } else { document.getElementById("listingInfo").innerHTML = ""; // no link if (elem.getAttribute("data-imglink") == "-") { elem.infoImg = document.createElement("IMG"); elem.infoImg.loading = "lazy"; elem.infoImg.alt = elem.getElementsByTagName("STRONG")[0].innerHTML; elem.infoImg.src = elem.getAttribute("data-imgsrc"); document.getElementById("listingInfo").appendChild(elem.infoImg); // with link } else { elem.infoA = document.createElement("A"); elem.infoA.href = elem.getAttribute("data-imglink"); if ((elem.infoA.href.search("tel:") != 0) && (elem.infoA.href.search("mailto:") != 0)) { elem.infoA.target = "_blank"; } elem.infoA.rel = "noopener nofollow"; document.getElementById("listingInfo").appendChild(elem.infoA); elem.infoImg = document.createElement("IMG"); elem.infoImg.loading = "lazy"; elem.infoImg.alt = elem.getElementsByTagName("STRONG")[0].innerHTML; elem.infoImg.src = elem.getAttribute("data-imgsrc"); elem.infoA.appendChild(elem.infoImg); } } } </script>'; } elseif (isset($wpda_shortcode_args['country']) && isset($wpda_shortcode_args['port'])) { global $wpdb; $wpdb->flush(); unset($result,$slide); $sitecountry = $wpdb->esc_like($wpda_shortcode_args['country']); $portservice = '%' . $wpdb->esc_like($wpda_shortcode_args['port']) . '%'; $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM company WHERE company_ports_ads_approval = %d AND company_country LIKE %s AND company_ports_code_list LIKE %s ORDER BY company_ports_ads_type ASC, company_name DESC", 1, // an untrusted integer (function will do the sanitization for you) $sitecountry, // an unescaped string (function will do the sanitization for you) $portservice, // an unescaped string (function will do the sanitization for you) ) ); echo '<div class="clearfix" style="float: left; width: 50%;">'; echo '<h6 style="padding: 0; margin: 5px; margin-bottom: 0px; color: #000000;">MLO / Feeder / NVOCC</h6>'; $slide = 0; foreach ($result as $row) { if ($row->company_ports_ads_type == 'right' && $slide == 0) { $slide += 1; echo '</div>'; echo '<div class="clearfix" style="float: left; width: 50%;">'; echo '<h6 style="padding: 0; margin: 5px; margin-bottom: 0px; color: #000000;">Consolidator / Forwarder</h6>'; } echo '<div class="clearfix" style="float: left; width: 50%;">'; echo '<a rel="noopener nofollow" target="_blank" href="' . $row->company_ports_ads_link . '" style="display: block; margin: 3px;">'; echo '<img loading="lazy" src="' . $row->company_ports_ads_imgsrc . '" alt="' . $row->company_name . '" style="width: 100%; height: auto;">'; echo '</a>'; echo '</div>'; } echo '</div>'; } ?>Now that I’ve written the full hardcode, I’m not sure if I can make the dynamic version. Its more complex than I expected.
For those who want some sort of quick reference, the format is as such:
<?php // Enable the use of custom (defined) parameters. // This example defines custom parameters "arg1" & "arg2" only. global $wpda_shortcode_args; if (isset($wpda_shortcode_args['arg1']) && isset($wpda_shortcode_args['arg2']) /* && ... more custom parameters here*/) { // Enable / "initialise/clean" needed variables. global $wpdb; $wpdb->flush(); unset($result); $arg1 = $wpdb->esc_like($wpda_shortcode_args['arg1']); // no wildcard. $arg2 = '%' . $wpdb->esc_like($wpda_shortcode_args['arg2']) . '%'; // wildcard before and after. // The query itself to pull data from database. $result = $wpdb->get_results( $wpdb->prepare( '', // SQL Query using parameters such as %s / %d / %f for security. // list parameter values as needed in the correct order. Only $arg1 & $arg2 listed in this example. $arg1, // an unescaped string (%s), integer (%d) or float (%f)... (function will do the sanitization for you) $arg2 // an unescaped string (%s), integer (%d) or float (%f)... (function will do the sanitization for you) ) ); // make variables for "counting" or echo anything needed before looping data rows here. foreach ($result as $row) { // loop over each data row. //custom code here to use the database table values. $col_1_value = $row->table_column1; // example to get data of first column as a variable. } // the rest of custom code not needing data from database table. } ?>The comprehensive example with mix of HTML, JS, CSS, PHP by @peterschulznl is best seen here:
https://code-manager.com/code/?wpda_search_column_code_name=code-manager-publication-layout-panel- This reply was modified 4 years, 5 months ago by rlohmj.
Hi @peterschulznl ,
Once again I want to mention how awesome your plugins are!
Here’s an update regarding my hardcoded version and a question (at the bottom).
The full working code for “Home Carousels” Sample (rotloc type “sidebar” is prerequisite for using rotloc type “body”):
<?php global $wpda_shortcode_args; if (isset($wpda_shortcode_args['country']) && isset($wpda_shortcode_args['rotloc'])) { global $wpdb; $sitecountry = $wpdb->esc_like($wpda_shortcode_args['country']); $rotloc = '%' . $wpdb->esc_like($wpda_shortcode_args['rotloc']) . '%'; $approveads = 1; $result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM rotatingads WHERE rotads_loc LIKE %s ORDER BY rotads_set ASC", $rotloc, // an unescaped string (function will do the sanitization for you) ) ); switch ($wpda_shortcode_args['rotloc']) { case 'sidebar': echo '<style> /* Style Sidebar */ #featuredSideBar>div { box-sizing: border-box; width: 100%; margin-bottom: 5px; } #featuredSideBar>div:last-child { margin-bottom: 0px; } </style>'; echo '<div id="featuredSideBar">'; $slide = 0; echo '<div class="slideSet">'; foreach ($result as $row) { if ($slide != $row->rotads_set && $slide != 0) { $slide += 1; echo '</div>'; echo '<div class="slideSet">'; } elseif ($slide == 0) { $slide += 1; } if (substr($row->rotads_link, 0, 4) == 'tel:' || substr($row->rotads_link, 0, 7) == 'mailto:') { echo '<a rel="noopener nofollow" href="' . $row->rotads_link . '" style="text-decoration: none;">'; } else { echo '<a rel="noopener nofollow" target="_blank" href="' . $row->rotads_link . '" style="text-decoration: none;">'; } echo '<img loading="lazy" src="' . $row->rotads_imgsrc . '" alt="' . $row->rotads_desc . '" style="width: 100%; height: auto;">'; echo '</a>'; } echo '</div>'; echo '</div>'; echo '<script> var SlideIndex = []; var SlideSet = []; for (var setnum = 0; setnum < jQuery("#featuredSideBar .slideSet").length; setnum++) { SlideIndex[setnum] = 0; SlideSet[setnum] = jQuery("#featuredSideBar .slideSet:eq(" + setnum + ") > a"); } SlideMaker(); function SlideMaker() { for (var setnum = 0; setnum < jQuery("#featuredSideBar .slideSet").length; setnum++) { SlideIndex[setnum] = ShowSlides(SlideSet[setnum], SlideIndex[setnum] += 1); } slideTimeout = setTimeout(function() { SlideMaker(); }, 2000); }; function ShowSlides(s, n, t) { if (n > s.length) { n = 1; } if (n < 1) { n = s.length; } for (var i = 0; i < s.length; i++) { s[i].style.display = "none"; if (t != null) { t[i].classList.remove("activeThumbDot"); } } s[n - 1].style.display = "block"; if (t != null) { t[n - 1].classList.add("activeThumbDot"); } return n; }; </script>'; break; case 'body': echo '<style> /* Position the image container (needed to position the left and right arrows) */ #featuredBody { position: relative; } /* Next & previous buttons */ #featuredBody .prev, #featuredBody .next { cursor: pointer; position: absolute; top: 0; width: auto; padding: 5px 10px; margin-top: -27px; color: rgba(0, 0, 0, 0.5); background-color: rgba(255, 255, 255, 0.3); font-weight: bold; font-size: 10px; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; -webkit-user-select: none; -ms-user-select: none; -moz-user-select: none; -o-user-select: none; user-select: none; } /* Position the "next button" to the right */ #featuredBody .next { right: 0; } /* On hover, add a black background color with a little bit see-through */ #featuredBody .prev:hover, #featuredBody .next:hover { color: white; background-color: rgba(0, 0, 0, 0.8); } /* Add a pointer when hovering over the thumbnail images */ .cursor { cursor: pointer; } /* The dots/bullets/indicators */ .thumbDot { cursor: pointer; height: 11px; width: 11px; margin: 7px 2px; background-color: #bbb; border-radius: 50%; display: inline-block; } .activeThumbDot, .thumbDot:hover { background-color: #717171; } </style>'; echo '<div id="featuredBodyMiniPics" style="text-align:center; margin: 0; padding: 0; line-height: 0.5;">'; for ($i = 1; $i <= $wpdb->num_rows; $i++) { echo '<span class="thumbDot" onclick="CurrentSlide(' . $i . ')"></span>'; } echo '</div>'; echo '<div id="featuredBody" style="width: 100%; margin: 0 auto; padding: 0;">'; echo '<div class="slideSet">'; foreach ($result as $row) { echo '<a rel="noopener nofollow" target="_blank" href="' . $row->rotads_link . '" style="text-decoration: none;">'; echo '<img loading="lazy" src="' . $row->rotads_imgsrc . '" alt="' . $row->rotads_desc . '" style="width: 100%; height: auto;">'; echo '</a>'; } echo '</div>'; echo '<a class="prev" onclick="PlusSlides(-1)">❮</a>'; echo '<a class="next" onclick="PlusSlides(1)">❯</a>'; echo '</div>'; echo '<script> var slideTimeout; var thumbs = document.getElementById("featuredBodyMiniPics").getElementsByClassName("thumbDot"); var bodyslides = document.getElementById("featuredBody").getElementsByClassName("slideSet")[0].getElementsByTagName("A"); var slideIndex = Math.floor(Math.random() * bodyslides.length); function SlideActive() { slideIndex = ShowSlides(bodyslides, slideIndex += 1, thumbs); slideTimeout = setTimeout(function() { SlideActive(); }, 2000); }; function PlusSlides(n) { clearTimeout(slideTimeout); slideIndex = ShowSlides(bodyslides, slideIndex += n, thumbs); slideTimeout = setTimeout(function() { SlideActive(); }, 5000); }; function CurrentSlide(n) { clearTimeout(slideTimeout); slideIndex = ShowSlides(bodyslides, n, thumbs); slideTimeout = setTimeout(function() { SlideActive(); }, 5000); }; SlideActive(); </script>'; break; default: break; } } ?>Going to work on the “Product List” and “Store List” now.
By the way, I notice that “PHP Shortcode” type was the only type with custom parameters tutorial in the DOCS. Can custom parameters be used in the other shortcode types as well?
Hi @peterschulznl ,
Oh Wow!
Thanks for telling me about your Code Manager plugin.I’ll try out my hardcoded PHP code first before working on the flexible one.
The ability to add custom parameters should make it possible for the flexible version.I’ll give an update if the hardcoded one works once its complete.
Thanks!
Sample ideal look from some other site:
1) example home page has carousel ads banner/img at sidebar and body:
home carousels
– the images/banners has hyperlink to relevant pages/sites.
2) example product category page has a header (red dots), 2 categories (black dots) and several products (green & orange dots)
product list initial load
– the images/banners has hyperlink to relevant product pages/sites.
3) example store category page has a list on the left side and an “IMG” area on the right.
store list initial load
– “IMG” area has some placeholder text to guide people to click something from the list.
1st click
– IMG banner shown after clicking something on the list.
2nd click
– IMG banner is replaced with new IMG banner when clicking something else on the list.
non banner type
– Example of non-IMG banner showing some details of the store.I was allowed to see whats under the hood for those pages on that sample site and to modify them for my own use.
They used a json data array to store the info on each relevant page and used javascript to “create” the innerHTML in a procedural manner such that the only difference between similar page types is the json data only.Example <script> used in sample (1) in its entirety, excluding the json data:
/** * Add/Change images to the list using the function "processRotatingData()". * * Format of the function "processRotatingData()": * processRotatingData([{ * "loc": "{sidebar / body}", * "set": "{set number}", * "desc": "{image short description / Company Name}", * "source": "{image source}", * "link": "{image hyperlink}" * }, * { * "loc": "{sidebar / body}", * "set": "{set number}", * "desc": "{image short description / Company Name}", * "source": "{image source}", * "link": "{image hyperlink}" * } * ]); * * For image sets that "rotate", use the same {set number}. * "loc": "sidebar" starts with first image in the same set. * "loc": "body" starts with a random image in the same set. */ // Initiate JSON data processing processRotatingData(some JSON data); // Process the JSON data function processRotatingData(rows) { // Iterate all rows and add slides for (var i = 0; i < rows.length; i++) { // Check last slide in set to start rotating var startRotate; if (i == (rows.length - 1)) { startRotate = true; } else { if (rows[i].set != rows[i + 1].set) { startRotate = true; } else { startRotate = false; } } slides_add(rows[i].loc, rows[i].set, rows[i].desc, rows[i].source, rows[i].link, i, startRotate); } } // append image to list and rotate when ready function slides_add(Loc, sI, Desc, Source, Link, thumbI, startRotate) { this.div = document.createElement("DIV"); this.div.style.display = "none"; this.div.className = "slideSet" + sI; if (Loc == "body" && document.getElementById("featuredBody") != null) { document.getElementById("featuredBody").appendChild(this.div); // thumb dots this.spanDots = document.createElement("SPAN"); this.spanDots.className = "thumbDot"; document.getElementById("featuredBodyMiniPics").appendChild(this.spanDots); this.spanDots.onclick = function () { currentSlide(thumbI + 1); }; // thumbnails /*this.divMini = document.createElement("DIV"); this.divMini.className = "miniPicContainer"; document.getElementById("featuredBodyMiniPics").appendChild(this.divMini); this.imgMini = document.createElement("IMG"); this.imgMini.className = "miniPic cursor"; this.imgMini.style.width = "20%"; this.imgMini.loading = "lazy"; this.imgMini.style.height = "auto"; this.imgMini.src = Source; this.imgMini.alt = Desc; this.imgMini.onclick = function() {currentSlide(thumbI+1);}; this.divMini.appendChild(this.imgMini);*/ } if (Loc == "sidebar" && document.getElementById("featuredSideBar") != null) { document.getElementById("featuredSideBar").appendChild(this.div); } this.a = document.createElement("A"); this.a.rel = "noopener nofollow"; this.a.style.textDecoration = "none"; if ((Link.search("tel:") != 0) && (Link.search("mailto:") != 0)) { this.a.target = "_blank"; } this.a.href = Link; this.div.appendChild(this.a); this.img = document.createElement("IMG"); this.img.loading = "lazy"; this.img.style.width = "100%"; this.img.style.height = "auto"; this.img.src = Source; this.img.alt = Desc; this.a.appendChild(this.img); // rotate if ready if (startRotate) { // only show selected image this.showSlides = function (s, n, t) { if (n > s.length) { n = 1; } if (n < 1) { n = s.length; } for (var i = 0; i < s.length; i++) { s[i].style.display = "none"; if (t != null) { t[i].classList.remove("activeThumbDot"); } } s[n - 1].style.display = "block"; if (t != null) { t[n - 1].classList.add("activeThumbDot"); } return n; }; if (Loc == "body" && document.getElementById("featuredBody") != null) { // prev & next buttons this.aPrev = document.createElement("A"); this.aPrev.className = "prev"; this.aPrev.innerHTML = "❮"; this.aPrev.onclick = function () { plusSlides(-1); }; document.getElementById("featuredBody").appendChild(this.aPrev); this.aNext = document.createElement("A"); this.aNext.className = "next"; this.aNext.innerHTML = "❯"; this.aNext.onclick = function () { plusSlides(1); }; document.getElementById("featuredBody").appendChild(this.aNext); // set thumbnail width /*var thumbs = document.getElementById("featuredBodyMiniPics").getElementsByClassName("miniPicContainer"); for (var i = 0; i < thumbs.length; i++) { thumbs[i].style.width = "calc(100% / " + thumbs.length + ")"; }*/ var thumbs = document.getElementById("featuredBodyMiniPics").getElementsByClassName("thumbDot"); // get slides var slides = document.getElementById("featuredBody").getElementsByClassName("slideSet" + sI); var slideIndex = Math.floor(Math.random() * slides.length); // set slideshow functions var slideTimeout; this.slideActive = function () { slideIndex = showSlides(slides, slideIndex += 1, thumbs); slideTimeout = setTimeout(function () { slideActive(); }, 2000); }; this.plusSlides = function (n) { clearTimeout(slideTimeout); slideIndex = showSlides(slides, slideIndex += n, thumbs); slideTimeout = setTimeout(function () { slideActive(); }, 5000); }; this.currentSlide = function (n) { clearTimeout(slideTimeout); slideIndex = showSlides(slides, n, thumbs); slideTimeout = setTimeout(function () { slideActive(); }, 5000); }; // start rotation slideActive(); } if (Loc == "sidebar" && document.getElementById("featuredSideBar") != null) { var slides = document.getElementById("featuredSideBar").getElementsByClassName("slideSet" + sI); var slideIndex = 0; this.interval = setInterval(function () { slideIndex = showSlides(slides, slideIndex += 1); }, 2000); slideIndex = showSlides(slides, slideIndex += 1); } } }Example <script> used in sample (3):
// The JSON data (if "bimg" == "-", it is Text Listing.) var jsonData = [ { "cname": something, "caddress": something, "ctel": something, "cemail": something, "cweb": something, "bimg": something }, { "cname": something, "caddress": something, "ctel": something, "cemail": something, "cweb": something, "bimg": "-" } ]; // Initiate JSON data processing processData(jsonData); // Process the JSON data function processData(rows) { // Iterate all rows and add Listing entry for (var i = 0; i < rows.length; i++) { listings_add(rows[i].cname, rows[i].caddress, rows[i].ctel, rows[i].cemail, rows[i].cweb, rows[i].bimg); } } // Banner & Listing Script from here onwards. (Do not edit.) // append entry to list function listings_add(cName, cAddress, cTel, cEmail, cWebsite, imgSrc) { MIX OF: - something = document.createElement("something"); - something.style.something OR something.attribute = something; - document.getElementById("something").appendChild(something); - conditions to show "IMG Banner" or just "Text Listing", and other conditions... }You mentioned accessing the database directly using PHP and the WordPress class wpdb. I am trying to code it out right now.
Rather that hard coding it to fit my needs exactly, I wanted to make the code flexible to allow different “views” per se. If I’m not wrong, you are working on something similar for your “reports” feature for this plugin.
However, how do I include PHP codes into my website? I am not familiar with using PHP in WordPress. As mentioned before, I used Shortcoder to include my repetitive HTML/CSS/JS code snippets in specific pages, but the plugin does not allow the use of PHP.