WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] template_redirect question (2 posts)

  1. Jaroslav Suhanek
    Member
    Posted 2 years ago #

    so, i have this one question about one function that use template_redirect action hook.. for example i'll use this url mysite.com/portfolio
    that page/post don't exist, and i would like to skip that step.. i have image in my head, but dont know how to write it..

    when requested url at end has portfolio redirect to template portfolio.php an archive template

    can someone help? thanks in advance..

    p.s. portfolio is custom post type...

  2. Jaroslav Suhanek
    Member
    Posted 2 years ago #

    function portfolio_template_redirect() {
    		$url = $_SERVER['REQUEST_URI'];
    		$url = preg_match('/portfolio/', $url, $matches);
    		if($url) {
    			include('\..\portfolio.php');
    			exit;
    		}
    	}
    	add_action('template_redirect', 'portfolio_template_redirect');

    no need.. here it is....

    here's if you link to single portfolio is portfolio/something/

    `function portfolio_template_redirect() {
    $url = $_SERVER['REQUEST_URI'];
    $url = substr($url, -10);
    if($url == 'portfolio/') {
    $url = substr($url, 0, 9);
    } elseif($url == '/portfolio') {
    $url = substr($url, 1, 10);
    }
    if($url == 'portfolio') {
    include('\..\page-portfolio.php');
    exit;
    }

    }
    add_action('template_redirect', 'portfolio_template_redirect');`

Topic Closed

This topic has been closed to new replies.

About this Topic