Skip to content

Instantly share code, notes, and snippets.

@qwersk
qwersk / theme_options.php
Created May 18, 2017 13:56
CREATE THEME SETTINGS PAGE #WP #WORDPRESS
// https://www.sitepoint.com/create-a-wordpress-theme-settings-page-with-the-settings-api/
function theme_settings_page()
{
?>
<div class="wrap">
<h1>Настройка темы</h1>
<form method="post" action="options.php">
<?php
settings_fields("section");
@qwersk
qwersk / trim_char.js
Created May 24, 2017 03:00
TRIM CHAR IN STRING #JS #JAVASCRIPT
var x = '|f|oo||';
var y = x.replace(/^\|+|\|+$/g, '');
document.write(x + '<br />' + y);
@qwersk
qwersk / element_prop.php
Created May 31, 2017 04:41
GET ELEMENT PROPERTIES #BITRIX
<?php
$db_props = CIBlockElement::GetProperty($item["IBLOCK_ID"], $item["ID"], "sort", "asc", array());
$PROPS = array();
while($ar_props = $db_props->Fetch()){
$PROPS[$ar_props['CODE']] = $ar_props['VALUE'];
echo $PROPS[$ar_props['CODE']] . "<br />";
}
?>
@qwersk
qwersk / element_view_counter.php
Created May 31, 2017 05:26
GET ELEMENT VIEW COUNTER #BITRIX
$view_counter = 0;
if(CModule::IncludeModule("iblock")){
CIBlockElement::CounterInc($item["ID"]);
$res = CIBlockElement::GetByID($item["ID"]);
if($ar_res = $res->GetNext()){
$view_counter = $ar_res['SHOW_COUNTER'];
}
}
@qwersk
qwersk / on_close_print.js
Created June 6, 2017 02:09
AFTER CLOSE PRINT WINDOW #JS #JAVASCRIPT
function close_print(){
var beforePrint = function() {
console.log('Functionality to run before printing.');
};
var afterPrint = function() {
//console.log('Functionality to run after printing');
$("#animal_menu, .single-subnav, #footer-credits-wrap, #mainpage-header, #print_button, .legend").show();
$(".park_map_page").css("width", 1170);
};
@qwersk
qwersk / .htaccess
Created June 6, 2017 09:09 — forked from ScottPhillips/.htaccess
Common .htaccess Redirects
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
@qwersk
qwersk / get_subcategory_items.php
Created June 15, 2017 07:48
GET SUBCATEGORY ITEMS FROM CUSTOM TAXONOMY #WP #WORDPRESS
$publicationsWithoutTerms = new WP_Query(array(
'post_type' => 'doc',
'tax_query' => array(array(
'taxonomy' => 'category',
'field' => 'term_id',
'operator' => 'NOT IN',
'terms' => get_terms('category', array(
'fields' => 'ids'
))
))
// 163 - necessary category id
// "category" - taxonomy name
$children_id = get_term_children(163, "category");
foreach($children_id as $child){
$term = get_term_by("id", $child, "category");
$id = $term->term_id;
$name = $term->name;
$count = $term->count;
}
@qwersk
qwersk / get_category.php
Created June 18, 2017 10:56
GET CATEGORY ID #JOOMLA
$app = Jfactory::getApplication();
$input=$app->input;
if ($input->getCmd('option')=='com_content'
&& $input->getCmd('view')=='article' ){
$cmodel = JModelLegacy::getInstance('Article', 'ContentModel');
$catid = $cmodel->getItem($app->input->get('id'))->catid;
echo $catid;
}
@qwersk
qwersk / current_url.php
Created June 20, 2017 04:36
GET CURRENT URL #PHP
function request_url()
{
$result = ''; // Пока результат пуст
$default_port = 80; // Порт по-умолчанию
// А не в защищенном-ли мы соединении?
if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS']=='on')) {
// В защищенном! Добавим протокол...
$result .= 'https://';
// ...и переназначим значение порта по-умолчанию