我想在管理员端上传PDF文件的自定义字段,在这里我可以使用自定义代码或任何类型的插件为任何帖子选择任何PDF文件。
你能推荐我解决问题的方法吗?
<?php
$array=array(\'posts_per_page\'=>2, \'post_type\'=>\'post\');
$mypost=get_posts($array);
//print_r($mypost);
foreach($mypost as $values)
{
//print_r($mypost);
echo "<p>" .$values->post_title."</p>";
echo "<p>" .$values->post_content."</p>";
echo "<p>" .get_the_post_thumbnail($values->ID, \'thumbnail\', array( \'class\' => \'thumbnail text-center\' ))."</p>";
echo \'<p>\' . date_i18n(\'d F Y\', strtotime($values->post_date)) .\'</p> \';
//$ca = get_the_category($values->ID);
//print_r($ca);
//echo $ca[0]->name;
$pdf_file = get_field(\'pdf\');
print_r($pdf_file);
if( $file ) {
echo \'<a href="\'.$pdf_file.\'">Download File</a>\';
}
}
?>
SO网友:dhirenpatel22
请查找我已更正的以下代码。。。。在If条件下,您的代码有一个小问题。。
<?php
$array=array(\'posts_per_page\'=>2, \'post_type\'=>\'post\');
$mypost=get_posts($array);
//print_r($mypost);
foreach($mypost as $values)
{
//print_r($mypost);
echo "<p>" .$values->post_title."</p>";
echo "<p>" .$values->post_content."</p>";
echo "<p>" .get_the_post_thumbnail($values->ID, \'thumbnail\', array( \'class\' => \'thumbnail text-center\' ))."</p>";
echo \'<p>\' . date_i18n(\'d F Y\', strtotime($values->post_date)) .\'</p> \';
//$ca = get_the_category($values->ID);
//print_r($ca);
//echo $ca[0]->name;
$pdf_file = get_field(\'pdf\');
print_r($pdf_file);
if( $pdf_file ) {
echo \'<a href="\'.$pdf_file.\'">Download File</a>\';
}
}
?>