wordpress display pages - wordpress

I use plugin wp-type
The wp-type plugin is used for making custom pages.
You can add for example a new field of type "file" and display the filelink in the page with the following code :
<?php
echo(types_render_field("file", array("title"=>"Download", "link"=>"true")));
?>
My problem is when I try to display files : in the main page everything's ok, but when I try to display the list of the posts with index.php it doesn't work.
This problem appears only with pages for posts I use :
<?php while (have_posts()) : the_post();
echo(types_render_field("file", array("title"=>"Download", "link"=>"true")));
endwhile;?>
and it works well.
Please help me to display all pages in index.php and each page file I try this :
<?php while (wp_list_pages( ));
echo(types_render_field("file", array("title"=>"Download", "link"=>"true")));
endwhile;?>

Replace your code to display page list:
while (wp_list_pages( )); to while (wp_list_pages( )):

Related

What is the url for page-test.php?

I create a file page-test.php in my template directory.
page-test.php
<?php echo "Hello"; ?>
What is the url for this page?
But it's not working...
i want to find the url for display the php file "page-test.php"
You can put this line to create the page template in WordPress
<?php /* Template Name: Example Template */ ?>
and then write your code in this PHP file
<?php echo "Hello"; ?>
After that, assign this page template to the admin area,
Reference: https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-custom-page-templates-for-global-use
I hope it might be helpful to you!

template management with wordpress (underscore boilerplate)

I am using underscore to develop a wordpress theme.
I have a custom post type name project, thus I have, for instance, this url: http://a.site.local/projects/a-beauty/.
I have in my template-parts/ directory the file content-projects.
$ cat template-parts/content-projects.php
<h1>Project</h1>
When I browse http://a.site.local/projects/a-beauty/, I have my title but also the sidebar and the footer (even if they do not appear in my content-project.php nor in index.php).
Where are those widgets coming from / loaded ?
Add conditions to the header, footer and sidebar.
For whole custom post archive:
<?php if( !is_post_type_archive( 'project' ) ) : ?>
// wrap the code you don't want to show on that archive
<?php endif; ?>
For custom post only:
<?php if( !is_singular( 'project' ) ) : ?>
// wrap the code you don't want to show on the post
<?php endif; ?>
If you want to put the code you WANT to show, remove the '!' before condition.
P.S.
You can put the whole content in a condition, but keep the
</div><!-- #page -->
<?php wp_footer(); ?>
</body>
</html>
otherwise the page will break :)
Please share some more code from your project so we can easy to understand the real problem.

Different header template for cms pages

I would like to use two different header templates for a website. One for the home page and in other cms pages the layout will be different. Can anyone please help me out with it?
There are two ways:
1-
<?php if (is_front_page()): ?>
home header codes
<?php endif; ?>
other pages header codes
2- You should have two header files like: header.php & header-home.php :
<?php
if (is_front_page()){
get_header('home');
}
else {
get_header();
}
?>

Wordpress Is there anyway to add specific class to home page body tag?

I am using a theme (Arcade Basic) in which the home page header image is resized differently from all other pages...
I would like to have the same header resizing on all pages included the home..
The resizing script is a .js script I don't want (I can't) to modify .
The resizing is triggered by the presence of the 'page' class in the body tag ..
# HOME PAGE
<body class="home blog only-on-home no-fittext basic">
# OTHER PAGES
<body class="page-template-default page page-id-1183 no-fittext basic">
If there anyway to add the 'page' class on the home page ?
Providing that you are using a specific page to act as your homepage and not just the default list of posts, you can add the following is_home() to check if you're on the homepage then add a class.
More information on the static front page setting.
<?php if ( is_home() ) : ?>
<body class="<?php body_class('homepage'); ?>">
<?php else : ?>
<body class="<?php body_class(); ?>">
<?php endif; ?>
you Can - but I can't say that treating all of your pages like a "page" won't come with bugs.
I would call the class something else.
find this in your header.php
<body <?php body_class('whatEverClassHere'); ?>>

Home Page Only Footer

I have a blog, http://sweatingthebigstuff.com and I would like to add an extra line in the footer which will display only from the homepage. I found this code, but it is not working for me. Do I have the wrong syntax or is there something else I can try to get this to work?
<?php if ( is_home() ) { ?>
text
<?php } ?>
Here is where footer.php is called
<?php include (TEMPLATEPATH . '/sidebar1.php'); ?>
<div class="cleared"></div>
<?php get_footer(); ?>
And here is the footer code:
text 2
Contact | Disclaimer | Privacy StatementCopyright © 2009-2010 Sweating The Big Stuff. All Rights Reserved.
and then some sitemeter crap.
is_home() sets a global var that doesn't seem to reset itself or re-evaluate, wp kinda strange.
Try putting wp_reset_query() at the end start of your if statement code
Actually, it'll be better to call it before as we can ensure the queries are reset
<?php wp_reset_query();
if ( is_home() ) { ?>
text
<?php } ?>
Now that the php is working, ideally you'd want the code above.
text
I just did a view source and I can plainly see the php code, which shouldn't be visible since it is meant to be parsed server side. The following shouldn't be there in the view source.... wrong file being edited?
<p>
<?php if ( is_home() ) { ?>
text
<?php } ?>
<wp_reset_query()>
<br />
<br />
The footer.php file should be located in wp-content/themes/nameofyourtheme folder
is_home() is a method that should return true or false. You need to implement this method somewhere. If blogspot doesn't implement this method for you, you need to do it yourself. For your website I think this function would do what you want:
<?php
function is_home(){
$r = $_SERVER['REQUEST_URI'];
return $r == '/' || $r == '' || $r == '/index.php';
}
if(is_home()) {
?>
text
<?php } ?>
And where you want the footer, put:
<?php include 'footer.php'; ?>
instead of the line:
<?php get_footer(); ?>
I believe your problem is that get_footer() is reading the footer as text, so it isn't executing the PHP beforehand. If you do it this way you can add as much PHP in the header as you want.
There is nothing wrong with your syntax, and when I view your page source, I see " text "
What is the file extension of your footer page? if it is "footer.php" then I shouldn't see the opening and closing terms for php (). php won't run unless the file extension is ".php"
as to a previous answer:
<?php wp_reset_query();?> should go BEFORE <?php if(is_home()){?>text<?php } ?> in this scenario. is_home() depends on a loop being present on the page. Maybe somewhere you used a custom query, or one of your plugins used a custom query that upset the default query vars. Like I said, use the reset statement before your if statement.
You need to modify the code to include a check for is_front_page() like so:
<?php
$ishomepage = ( is_home() || is_front_page() );
switch( $ishomepage )
{
case true :
echo 'Your homepage-only snippet of text goes here';
break;
case false :
default :
// Do nothing... or do something else...
break;
}
?>
Reference: WordPress Codex: is_front_page()
Default WP installations don't have a homepage defined, it uses your index.php and checks for other templates like a home.php template as a starting point (home.php only if your theme has it.) Here's a diagram from their online docs that shows how their hierarchy works: WordPress Template Hierarchy.
By default, WordPress shows your most recent posts on the front page
of your site. But many WordPress users want to have a static front
page or splash page as the front page instead. This "static front
page" look is common for those who wish to not have a "blog" look to
their site, giving it a more CMS (content management system) feel.
If you want to know how to set a static homepage, read this article and follow the instructions: Creating a Static Frontpage. When you set a static front page, is_home() will work as expected.

Resources