Skip to content

Instantly share code, notes, and snippets.

@prodeveloper
Last active August 29, 2015 14:06
Show Gist options
  • Save prodeveloper/354051d5ee9c4141579c to your computer and use it in GitHub Desktop.
Save prodeveloper/354051d5ee9c4141579c to your computer and use it in GitHub Desktop.
Retrieving Post Id From Link
class SimpleTitleParse implements TitleParserInterface {
function getTitle($url)
{
$url_parts=explode('/',$url);
$title=array_pop($url_parts);
return $title;
}
}
interface TitleParserInterface
{
function getTitle($url);
}
<?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