Yoast WordPress SEO Ajax前端更新程序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Yoast WordPress SEO Ajax前端更新程序相关的知识,希望对你有一定的参考价值。
This snippet shows how to retrieve information from the SEO plugin of Yoast, to be used for front-end use. This snippet is taken from the opensource free Nexus WP framework supporting front-end editing, custom layout and drag & drop.
function nxs_orderseo($a, $b) { if ($a["val"] == $b["val"]) { return 0; } return ($a["val"] < $b["val"]) ? -1 : 1; } function nxs_webmethod_getseoanalysis() { global $post; if ($postid == "") { webmethod_return_nack("postid niet meegegeven"); } { webmethod_return_nack("please install the WordPress Seo plugin by Yoast (1)"); } { } { require WPSEO_PATH.'admin/class-admin.php'; } require_once ABSPATH . 'wp-admin/includes/post.php'; $result["focuskw"] = wpseo_get_value('focuskw', $postid); if ($result["focuskw"] === false) { $result["focuskw"] = ""; } $result["title"] = wpseo_get_value('title', $postid); if ($result["title"] === false) { $result["title"] = ""; } $result["metadesc"] = wpseo_get_value('metadesc', $postid); if ($result["metadesc"] === false) { $result["metadesc"] = ""; } $wpseo_metabox = new WPSEO_Metabox(); $rendermode = "anonymous"; $postadapter = new stdClass(); $postadapter->ID = $postid; $postadapter->post_type = nxs_getwpposttype($postid); $postadapter->post_name = nxs_getslug_for_postid($postid); // the plugin of Yoast relies on global $post for some functions, where-as for // others it relies on an explicit argument $post... in both cases we mean the // same $post = $postadapter; // debug $result["debug_testpostid"] = $postadapter->ID; $result["debug_testpostname"] = $postadapter->post_name; $result["debug_testpostcontent"] = $postadapter->post_content; $calculatedresults = $wpseo_metabox->calculate_results($postadapter); // result can be a wp_error, for example, if the focuskey is not set if (is_wp_error($calculatedresults)) { $errorcodes = $calculatedresults->get_error_codes(); foreach ($errorcodes as $currentcode) { $thiserrors = $calculatedresults->get_error_messages($currentcode); $thiserror = $calculatedresults->get_error_message($currentcode); { $thiserror .= " (only showing first, skipping remaining errors)"; } $result["wperrors"][] = $thiserror; } } else { $snippet = $wpseo_metabox->snippet(); $result["snippet"] = $snippet; // enrich the scores $i = 0; foreach ($calculatedresults as $currentcalculatedresult) { $value = $calculatedresults[$i]["val"]; $score = wpseo_translate_score($value); $calculatedresults[$i]["indicator"] = $score; $i++; } // re-order $result["calculatedresults"] = $calculatedresults; } webmethod_return_ok($result); }
以上是关于Yoast WordPress SEO Ajax前端更新程序的主要内容,如果未能解决你的问题,请参考以下文章
php 显示主要类别(Yoast的WordPress SEO)
php 显示主要类别(Yoast的WordPress SEO)
php 显示主要类别(Yoast的WordPress SEO)
php 覆盖面包屑 - Yoast SEO WordPress插件