Last active
August 29, 2015 14:06
-
-
Save prodeveloper/354051d5ee9c4141579c to your computer and use it in GitHub Desktop.
Retrieving Post Id From Link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SimpleTitleParse implements TitleParserInterface { | |
function getTitle($url) | |
{ | |
$url_parts=explode('/',$url); | |
$title=array_pop($url_parts); | |
return $title; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface TitleParserInterface | |
{ | |
function getTitle($url); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Wp_post extends \Eloquent { | |
protected $connection='wordpress_blog'; | |
static function getIdByTitle($title){ | |
try{ | |
return static::wherePost_name($title)->firstOrFail(); | |
} | |
catch(Illuminate\Database\Eloquent\ModelNotFoundException $ex){ | |
throw new Exceptions\InvalidLink("Post Title Not Found"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment