Wordpress page content variable - wordpress

I am new to wordpress coding but familiar with standard HTML/CSS. With the help of various online tutorials I've finally gotten a good chunk of a simple HTML/CSS website converted to wordpress but Im missing out on some of the basics.
In this case, I am just trying to setup my template to work with the page.php file so that I can create pages through the wordpress admin console. I've figured out how to get the head.php, footer.php, and functions.php working for styles and js files but now I am struggling with what variable I need to place so that the title and content I enter into the page via the wordpress admin appears.
I've tried
1) using a div id=content to my page.php file --that didnt work
2) I've tried adding to my page.php file -- that didnt work
I cant seem to figure it out. Any help would be greatly appreciated. I am a definitley a beginner here so any help is greatly appreciated. Thanks!

This is a very basic template of a page.php in Wordpress.
<?php get_header(); ?>
<div>
<?php
if( have_posts() ) :
while ( have_posts() ) : the_post();
the_title(); // Outputs the title of the page
the_content(); // Outputs the content of the page
endwhile; // End of the loop.
endif;
?>
</div>
<?php get_footer(); ?>
Also, if you would like to store the title and content in php variables first, you can just call get_the_title() and get_the_content()
Please let me know if you are stuck.

Related

restrict viewing photos and article content on a wordpress site

I have a question, and i hope i am posting in the right place, if this topic belongs to another forum, please guide me where to post it.
the question is: i have a website created with WordPress and i am using the Jupiter theme, i need to hide some content (like hiding the last half of the article in a page) and disable the photos to be enlarged unless the visitor is a registered user, i need to know how to do that, and if there is a plugin to do that, i have tried "layered-popups-for-wordpress" and "optin-content-locker-layered-popups-addon" but they didn't work properly.
It might request a lot of effort for you to edit the theme on your own...You can use the_excerpt() insetead of the_content() for display info, and add a rule that only registered members can see, something like
if(is_user_logged_in()) {
the_content();
} else {
the_excerpt();
}
Do this while in the loop, of course...
These plugins might help you though
https://wordpress.org/plugins/tags/paid-content
If you're using WPMU might try this one
https://premium.wpmudev.org/project/pay-per-view/
I don't know of a plugin that does this automatically, but you can do it yourself if you are willing/able to do some minor theme development. Make a child theme of your Jupiter theme, and copy over the file content.php. There will probably be some part of the code that looks like this:
<?php if ( is_search() ) : ?>
<?php the_excerpt(); ?>
<?php else : ?>
...
Or something like that. The point is, the theme should already be set up to serve excerpted content for a search. You could either simply add code like this:
<?php if ( is_search() || !is_user_logged_in() ) : ?>
<?php the_excerpt(); ?>
<?php else : ?>
...
Or you could customize what non logged in users are seeing like this:
<?php if ( is_search() ) : ?>
<?php the_excerpt(); ?>
<?php else if (!is_user_logged_in()) : ?>
<!-- Your custom code display here -->
<?php endif; ?>
Hope that's helpful!
In order to hide certain parts of your content with just a simple shortcode you may give "Restrict Anonymous Access" plugin a try:
https://wordpress.org/plugins/restrict-anonymous-access/
Examples:
[member]My restricted content …[/member]
This shortcode can be placed wherever you need to hide something from logged-out users or even users of a certain user role can be addressed:
[member role="author"]My restricted content to users below author role …[/member]

Custom Wordpress sidebar not being retrieved

I'm tuning up a website made with Wordpress and I'm facing a small inconvenient:
I want to use a custom template for the posts in a specific category, so I have a single-4.php file that gets me a custom php file for any post in cat.id 4. That works great, now for the problem...
PROBLEM -->
I want to display a custom sidebar as well, so at the end of the single-4.php I add:
<?php get_sidebar( $evento ); ?>
As instructed in the Wordpress Codex, expecting to get my sidebar-evento.php file used istead of the default sidebar.php. But it doesn't work, instead it will just use the default behaviour instead. I have also tried "'single-evento'" instead. I know that the code line is being used because if I remove it, the sidebar area breaks ( dissapears and the page breaks).
My suspicion is that the Custom Sidebars plug-in is catching up right after I call for any sidebar and regardless of which one I'm requesting, it gets replaced. But it doesn't make much sense really. Because as you can see in my sidebar-evento.php:
<div id="right">
<h3>LINE TO CHECK IF SIDEBAR-EVENTO.PHP IS SHOWN</h3>
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<?php endif; // end sidebar widget area ?>
<?php if ( ! dynamic_sidebar( 'sidebar-3' ) ) : ?>
<?php endif; // end sidebar widget area ?>
</div></div>
Both things should happen: A) I get my custom text, then B) I get the other custom thingies as determined by the plug-in.
I hope I've been clear about what my problem is. Please bear in mind for your response that I have no PHP knowledge, I only do HTML and this is a sort of -charity- project, so I try to learn as I go. Meaning: step-by-step might be necessary! heh. Sorry!
Thank you very much in advance.
Try:
<?php get_sidebar( 'evento' ); ?>
This should pull in sidebar-evento.php

Need Help for my Custom Page Template

I'm very new to this PHP coding.. actually I'm not a programmer, but I need this help from anyone here...
Anyway, what I need help from you:
I have written a small snippet of Custom Page template, here it is:
------------------------------
<?php
/*
Template Name: MyCustomTemplate
*/
?>
<?php get_header(); ?>
<?php get_footer(); ?>
------------------------------
Now I have installed a wordpress slider plugin "Nivo Slider"..
Now I'm not understanding how do I call this plugin into my custom template...
Iam trying to achive home page with a Slider and some ads in it.. eg: I need my home page like this: www.papayaclothing.com/shop/
So, could anyone please provide me a code to work that?
Please try following code, make sure that slider you are trying to call is published:
<?php
//valid for Nivo Slider version < 1.8
echo do_shortcode('[nivoslider slug="my-slider"]');
?>
Let me know if my answer was helpful.

Wordpress Latest Blog Entries Plugin for Website

I would like to display my blog entries on my website in an iframe or whatever suggested method is. Can somebody please advice how to do that?
Thanks in advance.
Hi,
There are multiple options to do this I am mentioning three of them:
Menthod # 1
You can create a page template in wordpress and than using that page template create a page. Now you have the URL you can use that page in iFrame on any website.
Method # 2
Create a file at the root level of the server with this code:
<?php
// Include WordPress
define('WP_USE_THEMES', false);
require('wp-load.php');
query_posts('showposts=1');
while (have_posts()): the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<p>Read more...</p>
<?php endwhile; ?>
Now you can call this file in the iFrame and you have the latest posts.
Method # 3
You can use the rss feed from wordpress and either use PHP or jQuery to style it.
Thanks
Peachlabs

Simple Wordpress question

I've been programming for like 5 straight hours and my brain has kinda stopped functioning.
I can't remember how to do this:
There is a page called Blog on my website, and I need to show all posts from my blog on that page. The Blog page is using custom template... Therefore, it's not index.php...
Please help me, I'm lost :/
Include loop.php in your template. That is what gets and displays posts.
To show blog post on a custom markup template, you can use this procedure, to loop if there are any posts and print them via the_content function.
<?php
if (have_posts()) :
while (have_posts()) : the_post();
the_content();
endwhile;
endif;
?>

Resources