This is the solo-image version with no added text.
SELECT * FROM portfolio_projects
WHERE (
id = IFNULL((select min(id) from portfolio_projects where id > 39),0)
or id = IFNULL((select max(id) from portfolio_projects where id < 39),0)
)
ORDER BY date, id