Loading Ajax Portfolio from URL link

6 replies · opened Apr 28, 2016

JjaycbonillaApr 28, 2016

Is there any way I can load an Ajax Page from the 'portfolio-ajax.php' template file using a URL or link? I want to share the link of a portfolio post but there's no way I can share a link that will open a page via ajax.

For example: domain.com/portfolio#id

and from there opening in the ajax window:

<div id="portfolio-ajax-wrap">
<div id="portfolio-ajax-container"></div>
</div>

SSemicolon WebSTAFFApr 29, 2016

Hello,

This is Absolutely Possible! Simply add the following JS Code at the bottom of the Page just after the js/functions.js File Linking:


	jQuery(window).load(function(){
		var portfolioHash = window.location.hash.substr(1);
		if( portfolioHash ) {
			SEMICOLON.portfolio.loadItem( portfolioHash, '');
		}
	});

Now you can simply use: domain.com/portfolio#portfolio-item-1 to Open your Portfolio Items via AJAX.

This will definitely work fine. Let us know if we can help you with anything else or if you find any further issues.

JjaycbonillaApr 29, 2016

The code works great but, because I'm using this on a wordpress theme I'm calling posts via the data-loader which works great, so instead of calling the ID I need it to load ajax based on the data-loader link. The reason for this is becuase I am using pagination, and the portfolio I want to load might not be in the page.

Is this possible?

SSemicolon WebSTAFFMay 2, 2016

Hello,

Unfortunately, Loading the AJAX Portfolio using the data-loader parameter is currently not supported and a Call to the ID is required. so, according to what you mentioned, you can check if this ID is present on the Page and then trigger the AJAX Load. So, try using the following code:


	jQuery(window).load(function(){
		var portfolioHash = window.location.hash,
			portfolioHashTarget = window.location.hash.substr(1);
		if( portfolioHashTarget && $(portfolioHash).length > 0 ) {
			SEMICOLON.portfolio.loadItem( portfolioHashTarget, '');
		}
	});

This should fix your issue. Let us know if we can help you with anything else or if you find any further issues.

WWebink74Feb 24, 2017

Hello guys,

Both codes don't work for me.
I am also trying to display the id of each portfolio item when requested in order to :

-give a direct link to someone and load the item directly (without having to search it between all the realizations)
-to turn the portfolio page more user friendly allowing to use the previous and next button of the browser

Can I ask you some help?
Thanks

SSemicolon WebSTAFFMar 27, 2017

Hello,

  1. We have just checked out and it appears to be working fine for us. Can you please provide us with a Live URL so that we can check out the exact issue for this.

  2. Consider using the following code to replace the entire loadItem: function( portPostId, prevPostPortId, getIt ) Function Block in the js/functions.js File:

loadItem: function( portPostId, prevPostPortId, getIt ){
	if(!getIt) { getIt = false; }
	var portNext = SEMICOLON.portfolio.getNextItem(portPostId);
	var portPrev = SEMICOLON.portfolio.getPrevItem(portPostId);
	if(getIt == false) {
		SEMICOLON.portfolio.closeItem();
		$portfolioAjaxLoader.fadeIn();
		var portfolioDataLoader = $('#' + portPostId).attr('data-loader');
		$portfolioDetailsContainer.load(portfolioDataLoader, { portid: portPostId, portnext: portNext, portprev: portPrev },
		function(){
			SEMICOLON.portfolio.initializeAjax(portPostId);
			SEMICOLON.portfolio.openItem();
			$portfolioItems.removeClass('portfolio-active');
			$('#' + portPostId).addClass('portfolio-active');
			if( '#' + portPostId != window.location.hash ) {
				if( history.pushState ) {
					history.pushState( null, null, '#' + portPostId );
				} else {
					window.location.hash = '#' + portPostId;
				}
			}
		});
	}
},

Then, use the following code at the bottom of the Portfolio AJAX Page just after the js/functions.js JS File Linking:


	function loadPortfolioByHash(){
		var portfolioHash = window.location.hash,
			portfolioHashTarget = window.location.hash.substr(1);
		if( portfolioHashTarget && $(portfolioHash).length > 0 ) {
			SEMICOLON.portfolio.loadItem( portfolioHashTarget, '');
		}
	}

	jQuery(window).load(function(){
		loadPortfolioByHash();
	});

	window.addEventListener('hashchange', function (e) {
		loadPortfolioByHash();
	});

This will definitely work fine. Hope this Helps!

Let us know if we can help you with anything else or if you find any further issues.

WWebink74Mar 27, 2017

Sorry, I am on a localhost, I can't provide you the URL but I try to reproduce the issues on the live demo when possible.
I try it and come back to you

Have the same question, or something new?

Sign in to the Canvas dashboard to reply or open your own topic. Canvas owners get direct help from the SemiColonWeb team.

Reply on the dashboard