Local Research

function display_research_articles() {
// جلب البيانات من API
$data = wpgetapi_endpoint(‘ quotable1‘ , ‘ articles‘ , array(‘ debug‘ => false));

// إذا لم توجد بيانات
if (empty($data) || !is_array($data)) {
return ‘

No articles found.

‘ ;
}

// البحث والتصفية
$search_query = isset($_GET[‘ search‘ ]) ? sanitize_text_field($_GET[‘ search‘ ]) : ‘ ‘ ;
$filtered_data = array_filter($data, function($article) use ($search_query) {
return stripos($article[‘ title‘ ], $search_query) !== false ||
stripos($article[‘ authors‘ ], $search_query) !== false ||
stripos($article[‘ college‘ ], $search_query) !== false;
});

// Pagination
$per_page = 10;
$current_page = isset($_GET[‘ paged‘ ]) ? max(1, intval($_GET[‘ paged‘ ])) : 1;
$total_items = count($filtered_data);
$total_pages = ceil($total_items / $per_page);
$offset = ($current_page – 1) * $per_page;
$paginated_data = array_slice($filtered_data, $offset, $per_page);

// بداية HTML
$output = ‘

‘ ;

// عرض البيانات
foreach ($paginated_data as $article) {
$output .= ‘

‘ ;
}

$output .= ‘

Title Authors University Published Date Link
‘ . esc_html($article[‘ title‘ ]) . ‘ ‘ . esc_html($article[‘ authors‘ ]) . ‘ ‘ . esc_html($article[‘ college‘ ]) . ‘ ‘ . esc_html($article[‘ publishDate‘ ]) . ‘ View on Scopus

‘ ;

// Pagination Links
if ($total_pages > 1) {
$output .= ‘

‘ ;
for ($i = 1; $i <= $total_pages; $i++) { $output .= ‘ ‘ . $i . ‘ ‘ ;
}
$output .= ‘

‘ ;
}

$output .= ‘

‘ ;

return $output;
}
add_shortcode(‘ research_articles‘ , ‘ display_research_articles‘ );