Create a new file nextpreviouspagination.phtml at app/design/frontend/Vendor/theme/Magento_Catalog/templates/product/view/.
Add following code in this new file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<?php $productId = $block->getProduct()->getId(); $categoryIds = $block->getProduct()->getCategoryIds(); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $nxtProduct = $objectManager->create('Magento\Catalog\Model\Product'); $prvProduct = $objectManager->create('Magento\Catalog\Model\Product'); $category = $objectManager->create('Magento\Catalog\Model\Category')->load($categoryIds[0]); $categoryProduct = $category->getProductCollection()->addAttributeToSort('position', 'asc'); $categoryProduct->addAttributeToFilter('status',1); $categoryProduct->addAttributeToFilter('visibility',4); $categoryProductIds = $categoryProduct->getAllIds(); $position = array_search($productId, $categoryProductIds); // get position of the current product $nextPosition = $position+1; $previousPosition = $position-1; $keys = array_keys($categoryProductIds); if(in_array($nextPosition, $keys)){ $nextProduct = $nxtProduct->load($categoryProductIds[$nextPosition]); } if(in_array($previousPosition, $keys)){ $previousProduct = $prvProduct->load($categoryProductIds[$previousPosition]); } ?> <div class="previous_next"> <?php if(in_array($previousPosition, $keys)): ?> <a href="<?php print_r($previousProduct->getProductUrl()); ?>"><span>Previous </span></a> <?php endif; ?> <?php if(in_array($nextPosition, $keys)): ?> <a href="<?php print_r($nextProduct->getProductUrl()); ?>"><span>Next </span></a> <?php endif; ?> </div> |
Now open this file app/design/frontend/Vendor/theme/Magento_Catalog/layout/catalog_product_view.xml.
Add following code between body tag of the catalog_product_view.xml file:
1 2 3 4 5 |
<referenceContainer name="content"> <block class="Magento\Catalog\Block\Product\View\Description" name="product.info.nextpreviouspagination" template="product/view/nextpreviouspagination.phtml" /> </referenceContainer> <move element="product.info.nextpreviouspagination" destination="product.info.main" after="page.main.title"/> |
If you want get query string params in controller file,...
Create di.xml and add the below code Magemonkey/Redirect/etc/frontend/di.xml [crayon-6284612ae59c1896575558/] Create...
You can try below code to change local date to...
Step 1: First you need to add registration.php file in...
Step1 : Override message.js in current theme file on the...