我正在使用WordPress的默认类别小部件。 选择类别并从该窗口小部件输入标题后,我必须在自定义模板中显示该类别的帖子。
如何检索标题,类别ID等自定义数据?
答案 0 :(得分:4)
function rh_get_widget_data_for($sidebar_name) {
global $wp_registered_sidebars, $wp_registered_widgets;
$output = array();
$sibebar_id = false;
foreach ($wp_registered_sidebars as $sidebar) {
if ($sidebar['name'] == $sidebar_name) {
$sidebar_id = $sidebar['id'];
break;
}
}
if (!$sidebar_id) {
return $output;
}
$sidebars_widgets = wp_get_sidebars_widgets();
$widget_ids = $sidebars_widgets[$sidebar_id];
if (!$widget_ids) {
return array();
}
foreach ($widget_ids as $id) {
$option_name = $wp_registered_widgets[$id]['callback'][0]->option_name;
$key = $wp_registered_widgets[$id]['params'][0]['number'];
$widget_data = get_option($option_name);
$output[] = (object) $widget_data[$key];
}
return $output;
}
//call this function
rh_get_widget_data_for('Widget Name');
答案 1 :(得分:0)
我相信你想在自定义模板中显示小部件。
最好的方法是注册一个新的小部件区域
CREATE OR REPLACE FUNCTION get_project_launch_date
( p_form_id_param IN NUMBER )
RETURN VARCHAR2
AS
project_launch_date VARCHAR2(100);
temp TIMESTAMP;
temp1 VARCHAR2(100);
BEGIN
--fetching the doc created by information ;
SELECT ANSWER INTO project_launch_date
FROM table
WHERE QUESTION_ID = id
AND FORM_ID = p_form_id_param;
temp := to_timestamp(project_launch_date,
'YYYY-MM-DD"T"HH24:MI:SS.FF"Z"');
temp1 := TO_CHAR(temp,'DD/MM/YYYY HH12:MI:SS AM');
DBMS_OUTPUT.PUT_LINE('OUTPUT =' || temp1);
RETURN temp;
END;
并将其放在模板中以显示小部件。
<?php
/**
* Register our sidebars and widgetized areas.
*
*/
function shramee_widgets_init() {
register_sidebar( array(
'name' => 'Custom Template Widgets',
'id' => 'custom_template_widgets',
'before_widget' => '<div class="custom_template_widget">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
) );
}
add_action( 'widgets_init', 'shramee_widgets_init' );
?>
您不仅可以使用类别帖子小部件,还可以使用任何小部件:)