Viewing 18 posts - 1 through 18 (of 18 total)
  • Author
    Posts
  • #1022238

    Hiya

    I’ve been looking at altering the post format link for my blog posts so that if an ACF field exists for the post the link will redirect. I’ve found the reference in helper-post-format.php with the following but not sure where to add my ACF shortcode. Any help would be greatly appreciated.

    Thanks
    Richard

    /**
     *  The avia_link_content_filter checks if the beginning of the post is a url. If thats the case this url will be aplied to the title.
     *  Otherwise the theme will search for the first URL within the content and apply this URL
     */
    if(!function_exists('avia_link_content_filter'))
    {
    	function avia_link_content_filter($current_post)
    	{
    		//retrieve the link for the post
    		$link 		= "";
    		$newlink    = false;
    		$pattern1 	= '$^\b(https?|ftp|file)://[-A-Z0-9+&@#/%?=~_|!:,.;]*[-A-Z0-9+&@#/%=~_|]$i';
    		$pattern2 	= "!^\<a.+?<\/a>!";
    		$pattern3 	= "!\<a.+?<\/a>!";
    
    		//if the url is at the begnning of the content extract it
    		preg_match($pattern1, $current_post['content'] , $link);
    		if(!empty($link[0]))
    		{
    			$link = $link[0];
    			$markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false));
    			$current_post['title'] = "<a href='$link' rel='bookmark' title='".__('Link to:','avia_framework')." ".the_title_attribute('echo=0')."' $markup>".get_the_title()."</a>";
    			$current_post['content'] = preg_replace("!".str_replace("?", "\?", $link)."!", "", $current_post['content'], 1);
    		}
    		else
    		{
    			preg_match($pattern2, $current_post['content'] , $link);
    			if(!empty($link[0]))
    			{
    				$link = $link[0];
    				$current_post['title'] = $link;
    				$current_post['content'] = preg_replace("!".str_replace("?", "\?", $link)."!", "", $current_post['content'], 1);
    				
    				$newlink = get_url_in_content( $link );
    			}
    			else
    			{
    				preg_match($pattern3,  $current_post['content'] , $link);
    				if(!empty($link[0]))
    				{
    					$current_post['title'] = $link[0];
    					
    					$newlink = get_url_in_content( $link[0] );
    					
    				}
    			}
    		}
    
    		if($link)
    		{
    			if(is_array($link)) $link = $link[0];
    			if($newlink) $link = $newlink;
    			
    			$heading = is_singular() ? "h1" : "h2";
    
    			//$current_post['title'] = "<{$heading} class='post-title entry-title ". avia_offset_class('meta', false). "'>".$current_post['title']."</{$heading}>";
    			$current_post['title'] = "<{$heading} class='post-title entry-title' ".avia_markup_helper(array('context' => 'entry_title','echo'=>false)).">".$current_post['title']."</{$heading}>";
    			
    			//needs to be set for masonry
    			$current_post['url'] = $link;
    		}
    		else
    		{
    			$current_post = avia_default_title_filter($current_post);
    		}
    
    		return $current_post;
    	}
    }
    #1022795

    Hey Richard,

    I think you can add your acf code after this line of code:

    if($newlink) $link = $newlink;

    you can add:

    if( get_field( "mylink" ) ) $link = get_field( "mylink" );

    Hope it helps.

    Best regards,
    Nikko

    #1022982

    Hi Nikko

    I’ve added the code and included the custom field name instead “mylink” but nothing happens.

    I’m not placing the ACF shortcode in the post content but instead using the column on the right of the post. Will that affect how it outputs?

    Richard

    #1023181

    Hi Richard,

    You can see this code below from the code you posted:

    $current_post['url'] = $link;

    this basically just means that it just changes the current post’s url but not the content, so it will just change the link but content is still the same.
    Can you give us a link to the page where you want it to take effect? as well as give us admin access, so we can try to check the backend.
    Just post the details in private content, so it’s only the moderators who can view it.

    Best regards,
    Nikko

    #1023188

    Hi Nikko

    Ok thanks, here’s the login details so you can take a look.

    Thanks
    Richard

    #1023397

    Hi raslade,

    Thanks I’m getting this in the frontend (href is an error):

    <a href="Error: Function does not exist. Check name in shortcode or is function name is loaded." target="_blank">Agenda April 2016</a>

    I also Appearance > Editor isn’t available. Can we request for ftp access? so we can access the files as well and try to inspect further.

    Best regards,
    Nikko

    #1023526

    Hi Nikko

    Ignore the meeting agenda section, that’s another plugin i’ve been testing to replicate PDF links. FTP below

    Richard

    #1023971

    Hi raslade,

    I have checked it and noticed that the code you posted above had nothing to do with the shortcode you used, that’s why nothing is happening.
    The only thing I noticed is that the [php_function] shortcode that you used:

    <a href='[php_function name='download_report']' target="_blank">[post_title]</a></h3>

    isn’t defined that’s why I could see the error in the previous post. I’m not really familiar with the plugin you’re using but I think you can instead create your own shortcode which I think you can customize better.

    Best regards,
    Nikko

    #1024021

    Hi Nikko

    I’ve been testing another plugin but this is probably confusing the issue. Could you check back now.

    Richard

    #1024122

    Hi Richard,

    I think that’s better.
    Since you are using Blog Posts, you can override config-templatebuilder > avia-shortcodes > blog to your child theme.

    Best regards,
    Nikko

    #1024169

    Thanks, however i’m still having trouble getting the ACF shortcode to register having added:

    if( get_field( "mylink" ) ) $link = get_field( "mylink" );

    Richard

    #1024679

    Hi Richard,

    I have added a postslider folder under the shortcodes folder of your child theme and copied postslider.php from the enfold theme.
    Then after this code (line 468-480):

    if($format == 'link')
    {
    		$current_post = array();
    		$current_post['content'] = $entry->post_content;
    		$current_post['title'] =  $entry->post_title;
    
    		if(function_exists('avia_link_content_filter'))
    		{
    				$current_post = avia_link_content_filter($current_post);
    		}
    
    		$link = $current_post['url'];
    }

    I added this code:

    if( get_field( 'download_report') ) {
    	$link = get_field( 'download_report');
    }    

    Let us know if you need further assistance.

    Best regards,
    Nikko

    #1024758

    Hi Nikko
    Thanks for making the change and the documents are now showing via the ACF field. I’ve added a few more posts to the page and selected the format as links but now each blog posts block only shows the same link for each post even though I have selected different attachments.
    Richard

    #1024915

    Hi Richard,

    I tried checking your site again, however I’m getting:

    Error establishing a database connection

    Let us know if we are able to check again your site.

    Best regards,
    Nikko

    #1024992

    Hi Nikko
    Ops OK should be fine now.
    Richard

    #1025270

    Hi Richard,

    Glad to hear that, I have replaced:

    if( get_field( 'download_report') ) {
    	$link = get_field( 'download_report');
    }

    with:

    if( get_field( 'download_report', $the_id) ) {
    	$link = get_field( 'download_report', $the_id);
    }

    Let us know if you need further assistance.

    Best regards,
    Nikko

    #1025342

    Morning Nikko

    Spot on thank you so much. Excellent theme, excellent support as always.

    Richard

    #1025406

    Hi Richard,

    Glad that we could help you :)
    Feel free to comeback if you need further assistance.
    Thanks for using Enfold and have a great day!

    Best regards,
    Nikko

Viewing 18 posts - 1 through 18 (of 18 total)

The topic ‘Changing the URL of post format link’ is closed to new replies.