retrieve posted blog content in wordpress based on id or permalink - blogs

I hope somebody know the answer of my question.
How do I retrieve posted blog content in wordpress based on id or permalink? I need the API.
Thank you

Wordpress documentation is your friend: get_post
e.g:
<?php
$my_id = 7;
$post = get_post($my_id);
$content = $post->post_content;
?>

Related

Include html text inside a Drupal 8 generated link

I have a hard time to style a link via the Drupal 8 render structure.
This link needs to be displayed in my custom module:
$add_link = \Drupal::l('<i class="fa fa-cog"></i>' . t('Add new project'), $url);
So between de tags I want a Font awesome icon in front of the text.
But Drupal print all html out as readable text.
I also notice that the l() function is deprecated in Drupal 8.
So what is the best way to do this in the Drupal 8 render structure?
If, like me, you wanted to use a render array of #type => 'link' and include an icon with it then you can do the following:
<?php
use Drupal\Core\Render\Markup;
use Drupal\Core\Url;
$form['actions']['reset_password'] = [
'#type' => 'link',
'#title' => Markup::create('<span class="glyphicon glyphicon-cog"></span> Forgot / Reset Password'),
'#url' => Url::fromRoute('user.pass'),
];
Took me a while, but this should work. Your code has a $url variable which may work fine, but this code below also shows how i got my $url.
$url = new Url(
'entity.eab_contact_entity.edit_form', array(
'eab_contact_entity' => $entity->id(),
)
);
$icon_text = $this->t('<i class="fa fa-pencil"></i>');
$edit_link = \Drupal::service('link_generator')->generate($icon_text, $url);
It turns out that any text that goes into a link needs to be 'safe', so that malicious code cannot be injected etc. If you're curious, it was discussed at length here: https://www.drupal.org/node/2273923
The main point, though, and what makes the above code work for me and answers your question, is the $this->t() surrounding the font-awesome string '<i class="fa fa-pencil"></i>'. That renders it 'safe' and the link generated has the HTML we want, rather than just printing out the text of the HTML.
Finally, in case you are looking for help generating your URL, this tutorial has a lot of hints.
Or if you need to pass spectial chars like ­ or any HTML tag in your link title you can also use the following:
$link_text = Markup::create('<div>' . $node->getTitle() . '</div>');
$link = Link::fromTextAndUrl($link_text, $node->toUrl());

Does mediawiki allow me to make www.site.com/wiki/ the "main page" of the wiki?

...I know how to establish short URLs (using .htaccess) that remove the "index.php" from URLs. Now my Wiki main page URL looks like www.site.com/wiki/Main_page. However, i want it to simply look like www.site.com/wiki/ . Is it possible to do this without heavy modifications to the source code?
Yes, this can be done now. The main trick is to tell MediaWiki what the canonical URL of your main page is. To have the main page in the domain root:
$wgHooks['GetLocalURL'][] = function ( &$title, &$url, $query ) {
if ( $title->isExternal() || $query != '' && $title->isMainPage() ) {
$url = '/';
}
};
See http://laxstrom.name/blag/2015/08/31/mediawiki-short-urls-with-nginx-and-main-page-without-redirect/ for full details.

can we display other html page information in same page

I am building webpage with several pages.i don't want to use links to go to those pages. i have given the page numbers in the bottom of the page. but when i click that page number the page should information of other page should in the same page.how can i achieve this?
If you don't want to redirect to another page you have to use a frame (the easier way, but really uglier) or AJAX. The AJAX code is easy, if you need it I'll post by comment :)
Chris Coyier at CSS-tricks has a great article explaining a non-frame SEO friendly technique for doing just that.
var oXHR = new XMLHttpRequest();
oXHR.open("get", "page.php?num=1", true); // here you get the page you need
oXHR.onreadystatechange = function ()
{
if (oXHR.status != 200)
document.getElementById('page_displayed').innerHTML = "Error: " + oXHR.status + " " + oXHR.statusText;
else
document.getElementById('page_displayed').innerHTML = oXHR.responseText;
// here will be displayed your content
}
oXHR.send(null);
This is the AJAX code. Then in "page.php" you would have to write something like (I'll write in pseudo-code):
<?php
// ipotize you see 10 post for every page
$post = 10;
$page_num = $_GET['num'];
// select from database the content you need
$sql = "SELECT content FROM pages LIMIT 0, ".$post;
// OR (if you have more html contents for different pages)
// if ($page_num == 1)
{
?>
<html code here>
<?php
}
// in each case you must return some text, it will be displayed on your page
?>
Ask if you don't understand :)
Yes frames is going to be the best thing for you.
Is the link for details http://www.w3schools.com/html/html_frames.asp

Missing image in cakephp blog post

I am new to cakePHP and I am tring the blog example of cakePHP 1.3 book .
I correctly upload image in this blog example.The image name in database and image in DOCUMENT_ROOT/....correctly
but now I am wanted to show image in my blog with related post.
I am using this code for image upload...
function add() {
if (!empty($this->data)) {
if(isset($this->data["Image"]["image"]["name"])){
$file = new File($this->data["Image"]["image"]["name"]);
$ext = $file->ext();
if ($ext != 'jpg' && $ext != 'jpeg' && $ext != 'gif' && $ext != 'png') {
$this->Session->setFlash('You may only upload image files.');
}else{
if(move_uploaded_file($this->data["Image"]["image"] ["tmp_name"],$_SERVER["DOCUMENT_ROOT"]."test_om/blog/app/webroot/img/upload_image/"
. $this->data["Image"]["image"]["name"]) == true){
$this->data["Post"]["image"] = $this->data["Image"]["image"]["name"];
}
$this->Post->save($this->data);
$this->Session->setFlash('Your post has been saved.');
$this->redirect(array('action' => 'index'));
}
}
}
}
and i am showing image form this code
<?php echo $this->Html->image('/img/upload_image/1.gif'); ?>
and this show same image with all post.
but i am wanted to set specfic image with its related post....
If you are sure you are getting everything correct (in the database and the file where it should be) you should use something like this in the view.
<?php echo $this->Html->image($this->data['Post']['image']); ?>
this is assuming you are passing the data from the controller in the way described in the tutorial to a view view :)
if is an index view you should have a variable posts that have all post info, and in the view you will be in a loop like a foreach ($post as $post). Assuming this your view should have something like this:
<?php echo $this->Html->image($post['Post']['image']); ?>
Suggestion: use debug kit (cakephp plugin) so you can see what variables are passed down and the structure (like a pr($variable))
Hope all this helps you, if not, comment this post so i can try to extend my answer if needed

Phpbb3 sessions integration with existing site

I hope I am in the right place!!
http://www.phpbb.com/kb/article/phpbb3-cross-site-sessions-integration/
http://www.phpbb.com/kb/article/phpbb3-sessions-integration/
What I am trying to do is integrate the phpbb forum with my existing site. I have already looked at the links above, and it doesn't seem to work. I have copied this code
define('IN_PHPBB', true);
define('ROOT_PATH', "/path/to/forums");
if (!defined('IN_PHPBB') || !defined('ROOT_PATH')) {
exit();
}
$phpEx = "php";
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : ROOT_PATH . '/';
include($phpbb_root_path . 'common.' . $phpEx);
$user->session_begin();
$auth->acl($user->data);
into a loginforum.php file, which I include in every page I want the sessions to be kept. I have done the three steps indicated in the sessions integration section, but when I try to check whether the user is authenticated, it doesn't seem so. Using the same code here:
<?php
if ($user->data['user_id'] == ANONYMOUS){
echo 'Please login!';
}
else{
echo 'Thanks for logging in, ' . $user->data['username_clean'];
}
?>
I only get the "Please login" phrase, even when I login.
I've been over this for hours, I don't understand where the problem is. Shouldn't it work after the three miraculous steps?? :(
I would be thankful to anyone who would try to help!
Cheers,
Den
This appears to be a duplicate of this question
However, try this answer:
if ($user->data['username'] == 'Anonymous')
{
echo 'Please login!';
}