Sitemap: Should I dynamically update sitemap for dynamic content or create a page containing all the dynamic links

Say i have the following route http://<my-domain>/{category}/subjects/{id}/Sitemap: Should I dynamically update sitemap for dynamic content or create a page containing all the dynamic links

the ones in the brackets are dynamic, I’m struggling with what is better or any better way to let google crawl through all these dynamic links

Approach 1: manually doing the job by removing or adding the record to site map and updating <lastmod>

Approach 2: create a page that includes all those links and reference that page in sitemap.xml

The second approach can be generated as a plain html file which is generated from the server app. Or, a simple webform aspx page that dynamically generates those links without having to create an html file.

Load list of products from subcategory dynamically

I have a product page, where I want to list all of the products from a sub-category.

Category > Mtn > Series <- product page level.

Category > Mtn > Series > Model <- product sub category level.

          $  args = array(             'post_type' => 'product',              'posts_per_page' => 8,             'product_cat' => '**SubCategory goes here**',             'orderby'   => 'meta_value_num',             'meta_key'  => '_price',             'order' => 'asc'           );  $  loop = new WP_Query( $  args );             while ( $  loop->have_posts() ) : $  loop->the_post(); global $  product; ?>  show the producdts here.    <?php endwhile; ?>           <?php wp_reset_query(); ?> 

the code above works when I hard code the product_cat into the field,

How would I pass the subcategory of the current category into the product_cat field in the array dynamically for all products that fit in the same layout structure?

CSP: any way to prevent inline scripts dynamically created by a trusted external script?

Let’s say I have a simple web application which uses a single JavaScript (JS) file, loaded from its own domain, and has implemented the restrictive Content Security Policy (CSP) of default-src 'self'. There’s a stored XSS in it whereby the JS file will make an Ajax call to an API which would return some content stored in a database, and that content (which came from untrusted user input) has inline JavaScript in it. The JS file creates an element in the page’s document and sets its HTML content to the retrieved content. Let’s assume that this is the necessary way of doing what it needs to do, and let’s assume that sanitising/encoding the input is unfeasible. I know that user input should always be sanitised, just for the purposes of this question, skip this suggestion as a solution.

Is there any way to set a CSP such that this inline JavaScript, dynamically put onto the page by trusted JavaScript, is blocked?

Here’s a minimal working example (you may need to serve it from a simple HTTP server, e.g. php -S localhost:58000, rather than loading as an .html file)

csp-test.html:

<!DOCTYPE html> <html>   <head>     <meta charset="UTF-8" />     <meta http-equiv="Content-Security-Policy" content="default-src 'self'">     <script charset="utf-8">       console.log('script') // blocked, OK     </script>     <script src="csp-test.js" charset="utf-8"></script>   </head>   <body>     <img src="x" onerror="console.log('img')"/> <!-- blocked, OK -->   </body> </html> 

csp-test.js:

console.log('trusted ext script') // executed, OK i = document.createElement('img') i.src = 'y' i.addEventListener('error',   function(){ console.log('img by trusted ext script'); }) // executed, HOW TO BLOCK THIS? document.body.append(i) 

result:

enter image description here

Best way for dynamically loading page content

I want to have the MyAccount-page of WooCommerce on a single page (~7 different pages, some include only tables with information and others forms to modify data) and dynamically load the content fired through button click.

Its maybe a simple question but I have multiple methods in my mind and also tried some but aren’t sure which way to go.

Important criterias are safety and performance (loading-speed)

Method 1:

  • Have all forms and tables invisible on the main-page and just request the necessary data via (jQuery)-Ajax, populate everything and make it visible

But here Im not sure about the loading speed because i have a lot on uneccessary elements on my page.

Method 2

  • Prepare forms on seperate php files and load them via jQuery into the right place.

    $ .ajax({

        url: "wp-content/themes/childtheme/some.php",     type: 'post',     dataType: "html",     async: true,     success: function(result){          $  ("#content-target").html(result);     }, }) 

This seems to work, but its always statet, that Ajax calls should go over the admin_url(‘admin-ajax.php’) url. But then im not sure, what to return from the php function (in admin-ajax)

But im also wondering if php code on the target file going to be executed?

Method 3

  • Prepare forms on seperate php files and also load them via jQuery but via admin-ajax.php

This was the only solution which comes in my mind when i try to do this over the admin-url.

Then i would’ve a php code like this which is returning my file:

function jd_include_myaccount_content() { $  pagename = $  _POST['pagename']; ob_start(); $  target_file = ABSPATH . 'wp-content\themes\flatsome-child\woocommerce\myaccount\orders.php' ; require($  target_file); $  buffer = ob_get_clean(); return $  buffer; 

}

and JS:

$ (‘.account-link’).on(‘click’, function() { var name = $ (this).data(‘pagename’); $ .ajax({

        url: <?php echo(admin_url('admin-ajax.php')); ?>,         type: 'post',         dataType: "html",         async: true,         data: {           action: 'jd_include_myaccount_content',           'pagename': name         },         success: function(result){              $  ("#content-target").html(result);         }     })   }) 

But here i only get an internal server error. Not sure if this is possible this way.

Does someone know which of the approaches should be the best ones Im really confused?

save xevent target file in specific folder dynamically in sql server

i need to create an xevent in sql server to capture all the executed queries while my server is running and to save them in a file under a folder with the database name.

so my problem is i need to save the file in a dynamic path ( with variables..etc) :

here is the code : DECLARE @file varchar(50); declare @path nvarchar(250); SET @file = ‘D:\XE\’+DB_NAME() set @path = ‘D:\XE\’+DB_NAME()+’day’; EXECUTE master.dbo.xp_create_subdir @file CREATE EVENT SESSION newSession1 ON SERVER ADD EVENT sqlserver.sql_statement_completed ( ACTION (sqlserver.sql_text, sqlserver.tsql_stack, sqlserver.client_app_name, sqlserver.client_hostname, sqlserver.username ) WHERE ( sqlserver.database_name = ‘School’ ) ), ADD EVENT sqlserver.sql_statement_starting ( ACTION (sqlserver.sql_text, sqlserver.tsql_stack, sqlserver.client_app_name, sqlserver.client_hostname, sqlserver.username ) WHERE ( sqlserver.database_name = ‘School’)
) ADD target package0.event_file(SET filename=N@path) WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF) GO

this code shows an error in set Filename = @path.

any help please ?

PS: i need to do with the code because iam going to include it in c# project method. thanks in advance

dynamically create elements on button click

I’m using create guten blocks to create a custom block for my theme and I need to create a list item with an onClick.

<script> function addItem() {   var ul = document.getElementById("ul-item");   var li = document.createElement("li");   var input = document.createElement("input");   input.type = "text";   li.setAttribute("id", "li-item");   li.appendChild(input);   ul.appendChild(li); } </script>  <ul id='ul-item'>   <li id="li-item"><input type="text" value="" /></li> </ul> <button onClick='addItem()'>Add Item</button> 

see the fiddle https://jsfiddle.net/j2yp7ub9/

something like that I just don’t know how to do it in CGB and can’t find anything using google.

Mobile – Best way to dynamically add more fields to the form

I have a form so the user can issue an invoice, it is basically composed of comboboxes and 90% of the time the user will send the receipt with only one product, but rarely it will send with more than one, my question is whats the “best way” I can add a button or something so the user can add (and remove) more products to the receipt.

My current form:

enter image description here

Best options to page a dynamically updating list

We’ve got a list of very dynamic items. New items are frequently added to the list (maybe one every few seconds).

The items can also be re-arranged (say they’ve been sorted by ‘last updated’ and one is updated by the system).

Our problem comes with paging this list. If the user has it sorted by “latest”, and they’re looking at the top 20 paged items for, say, 20 seconds, then scroll down – 5-10 items might now have been created.

If we naively query the database to get items “20-40” (the next ‘page’, although it’s actually a scroll), we’ll get duplicate items.

We’ve spent quite a lot of effort in our backend to be able to query our list from a specific date – we send a “get me items 20-40 FROM THIS TIME” to the back end.

However, that’s quite a difficult requirement for the database schema and back-end, we can’t support some things we want to because we have to try keep duplicate records for this ‘history’.

Are there any generally accepted strategies for dealing with this kind of situation?