wordpress - Plugin not displaying function on page where shortcode is present -
this plugin i'm developing, it's function display csv file stored in plugin directory, html table; reason i'm writing manually rather using 1 of many existing plugins perform similar task is; need able use html output script's functions executed later, rather displaying data.
the shortcode functioning because isn't visible on page, nothing else appears on page.
as far know csv file i'm using test plugin isn't corrupted, can opened.
this content of book1.csv:
test1,test2,test3 a,b,c 1,2,3 4,5,6 7,8,9 10,11,12 13,14,15
<?php <table> <thead> <th> image </th> <th> name </th> <th> price </th> </thead> <tbody> <?php add_shortcode( "csv", "open_csv_file"); function open_csv_file() { $handle = fopen("book1.csv", "r"); while (($data = fgetcsv($handle, 1000, ",")) !== false): } ?> <?php <tr> <td><?= $data[1] ?></td> <td><?= $data[2] ?></td> <td>$<?= number_format($data[7], 2) ?></td> </tr> endwhile; } </tbody> </table> ?>
i found errors in code, first not getting output because
- } function closed in wrong place
- short tags <?= may not work if disabled in configuration
the following may work,
<?php add_shortcode( "csv", "open_csv_file"); function open_csv_file() { ?> <table> <thead> <th> image </th> <th> name </th> <th> price </th> </thead> <tbody> <?php $handle = fopen("book1.csv", "r"); while (($data = fgetcsv($handle, 1000, ",")) !== false): ?> <tr> <td><?php echo $data[1]; ?></td> <td><?php echo $data[2]; ?></td> <td>$<?php echo number_format($data[7], 2); ?></td> </tr> <?php endwhile; ?> </tbody> </table> <?php } ?>
Comments
Post a Comment