Answer the question
In order to leave comments, you need to log in
Seo php + mysql Modx?
Good day, at work, there was a task to do mass SEO for the site in sales using a template:
for a page with "such a template" in cms and a category, then make a generated header according to a template from Excel.
In the semi-manual mode, I did the task, 6000+ records, for one of the cities.
Then I was told to do the same with other cities. (If I had been told at once I would have done everything at once).
I did the last task for a week.
Deadline 2 days. The only logical solution is to duplicate the content from the completed pages to those that are not yet ready.
The template for generating title and description is essentially the same.
And then I looked at the number of unfinished records, there are more than 230+ thousand of them.
Here is the code I used:
<?php
ini_set("memory_limit", "4012M");
function sear($text,$word){
$pos = strpos($text, $word);
if ($pos === false) {
return false;
} else {
return true;
}
return false;
}
$sql = "
SELECT id,type,contentType,pagetitle,longtitle,alias,isfolder,template,class_key,content_type,uri FROM modx_site_content WHERE context_key <> 'contname' and context_key <> 'web' and template <> 172 and template <> 136 and template <> 138 and template <> 169 and template <> 148 and template <> 142 and template <> 0 and template <> 145 and template <> 135 and template <> 70 and template <> 38 and template <> 13
";
$sql1 = "SELECT id,type,contentType,pagetitle,longtitle,alias,isfolder,template,class_key,content_type,uri FROM modx_site_content WHERE context_key = 'contname' and template <> 172 and template <> 136 and template <> 138 and template <> 169 and template <> 148 and template <> 142 and template <> 0 and template <> 145 and template <> 135 and template <> 70 and template <> 38 and template <> 13"; //Выборка готовых полей
$statement = $modx->query($sql);
$out = $statement->fetchAll(PDO::FETCH_ASSOC);
$stat = $modx->query($sql1);
$ouo = $stat->fetchAll(PDO::FETCH_ASSOC);
foreach ($ouo as $ou){
foreach ($out as $data) {
if($data['type'] === $ou['type'] and
$data['contentType'] === $ou['contentType'] and $data['pagetitle'] === $ou['pagetitle'] and $data['longtitle'] === $ou['longtitle'] and $data['alias']=== $ou['alias'] and $data['isfolder']=== $ou['isfolder'] and $data['template'] === $ou['template'] and $data['class_key'] === $ou['class_key'] and $data['content_type'] === $ou['content_type'] and $data['uri'] === $ou['uri']){
$res1 = $modx->getObject('modResource',intval($ou['id']));
$t1 = $res1->getTVValue('MetaTitle');
$d1 = $res1->getTVValue('MetaDescription');
if(!sear($t1,'➤')){continue;} ////Если тайтл вообще есть
$res2 = $modx->getObject('modResource',intval($data['id']));
$t2 = $res2->getTVValue('MetaTitle');
$d2 = $res2->getTVValue('MetaDescription');
if($t1 === $t2 and $d1 === $d2){continue;} //Если ещё не отредактирован
if(sear($t2,'➤')){continue;} //Если ещё не отредактирован
$t1 = str_replace('','',$t1);
$d1 = str_replace('','',$d1);
$res2->setTVValue('MetaTitle',$t1);
$res2->setTVValue('MetaDescription',$d1);
$res2->save();
}
}
}
die;
$res1 = $modx->getObject('modResource',intval($ou['id']));
$t1 = $res1->getTVValue('MetaTitle');
$d1 = $res1->getTVValue('MetaDescription');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question