Whats the url that displays all posts in wordpress? - php

I simply want a link to my blog archives. They are just normal posts, but I cannot seem to find the right url for them to add to my menu.

right url for them to add to my menu.
http://yourwebsite.com/?post_type=post

You don't have to necessarily use a category to every post.
Actually the file to list all posts of any category and date is the index.php. You just write 'the loop' as told on codex.
So if you changed your index.php to make it as a fancy page and not the post list only, now you're trying to create another page to do that for you.
So, if you follow me, you're doing this the wrong way. What you should do is to create a separate page and assign it as the home page of your blog. It would then free the index.php file for you to use it as the blog list, as it is by default.

Assuming that you did it the correct way (as mentioned by Guilherme), you should have a page designated as the blog list page.
The URL for the blog list if using the page 'My Blog' to display posts and pretty links for the url should be something like http://mywebsite.com/my-blog.

<?php if ( is_front_page() && is_home() ) {
// Default homepage
echo "Default homepage";
} elseif ( is_front_page()){
echo "Static homepage";
// Static homepage
} elseif ( is_home()){
echo "Blog page";
// Blog page
} elseif ( is_page( 'cart' ) || is_cart()){
echo "cart";
// Blog page
} elseif (is_single()){
echo "is_single";
// Blog page
} elseif (is_product_category()){
echo "is_product_category";
}
else {
echo "Everything else";
// Everything else
} ?>

Related

Show one content on every desktop page, except on home. Show other content on mobile

I try to achieve the following on my Wordpress site:
Show content A on every Desktop page, except Home.
Show content B on every Mobile page, except Home.
Show content C on Home (regardless if it's Desktop or Mobile). FYI, Home has page ID 10.
This is my code:
<?php
add_action( 'astra_content_before' , 'text_insert', 5 );
function text_insert() {
global $post;
if((! $post->ID == 10) OR (!is_wp_mobile)){
echo "This will show up on all desktop pages but never homepage";
}
elseif((! $post->ID == 10) AND (is_wp_mobile)){
echo "This will show up on all mobile pages but not on homepage";
}
else {
echo "this will show up on home";
}
}
?>
But all it does, is showing "this will show up on home" on ALL pages. What am I missing?
Thanks!

How can I edit this code so that it only changes the Top Menu bar on my homepage when a user is logged in without changing the Main Menu?

I am using OceanWP theme to create my site.
I have two different menus on my homepage, I have a top menu and I also have a main menu. http://prntscr.com/pofn5r
I would like for the top menu to display different options for users who are logged in and users who are logged out.
I have used the following code which I placed in the functions.php file. I have also created two different menus for logged in and logged out users:
function my_wp_nav_menu_args( $args = '' ) {
if( is_user_logged_in() ) {
$args['menu'] = 'logged_in';
} else {
$args['menu'] = 'logged_out';
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
It seems to work in terms of showing different menus for users which are logged in and users which are logged out but the problem is that it also changes the main menu as well as the top menu.
prntscr.com/podv5e
I wanted the main menu to remain the same and just have the top menu change.
I was wandering whether there was a way I could adjust the code so that it would only apply to the top menu and not the main menu?
You could do something like:
function my_wp_nav_menu_args( $args = '' ) {
if( is_user_logged_in() ) {
echo "Here you put HTML code when logged in";
} else {
echo "Here you put HTML code when logged out"
}
}
since echo will work like it is writted directly into HTML

how do i restrict wordpress from displaying a specific post on the post page

i have a post with the following ids
$posts_id=array(1,2,3,4,5);
i don't feel like displaying every post on the post page. i want to exclude some post ids from the post page. Taking for example i want to remove post id with 2 and 3 from getting displayed.
how do i achieve this in wordpress. this is all i have.
<?php while(have_posts()) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile?>
<?php get_footer();?>
Use pre_get_posts() action like this:
function exclude_single_posts_home($query) {
if ($query->is_home() && $query->is_main_query()) {
$query->set('post__not_in', array(2,3));
}
}
add_action('pre_get_posts', 'exclude_single_posts_home');
And put this in your functions.php file.
This should affect your home page (if you've set your home to be posts page without having home.php the default page template should fall back to index.php).
Also check template hierarchy.
Use pre_get_posts() action. add this code in your themes function.php file
function exclude_post($query) {
if( is_home() ) {
//add condition in which page you don't want to display post.
//WordPress by default home page is post page
$query->set('post__not_in', array(2,3));
//add post id which you want to remove from listing ex: array(2,3)
}
return $query;
}
add_filter( 'pre_get_posts', 'exclude_post' );
Edit
Remove from other page
Used is_page (Page ID, title, slug of page ) to remove the post from particular page
function exclude_post($query) {
if( is_home() || is_page (Page ID, title, slug of page )) {
//add condition in which page you don't want to display post.
//WordPress by default home page is post page
$query->set('post__not_in', array(2,3));
//add post id which you want to remove from listing ex: array(2,3)
}
return $query;
}
add_filter( 'pre_get_posts', 'exclude_post' );

if else statement in PHP for Magento Site, need to hide on Homepage, checkout and success page

Here's what is currently working with not displaying on the homepage. And displaying on all other pages, need help not displaying on /checkout/cart/ and /onepage/ and onepage/successs.
<?php if(Mage::getBlockSingleton('page/html_header')->getIsHomePage()): ?>
<?php else: ?>
(Div I am trying to display only on pages other than homepage,checkout,success)
<?php endif; ?>
Please try this
$routeName = Mage::app()->getRequest()->getRouteName();
$identifier = Mage::getSingleton('cms/page')->getIdentifier();
if($routeName == 'cms' && $identifier == 'home') {
echo 'This is Magento Homepage.';
} else {
echo 'This is not a Magento Homepage.';
}
this should work for home page only .For hide on multiple pages you can create a array of pages and check if route name exist in that
thanks
place below code in your header file.
for home page :
<?php if ($this->getIsHomePage()){echo 'this is home page';}else{echo 'this is not home page';}
now we will take one variable $pageIdentifier for other then home page
<?php $pageIdentifier = Mage::app()->getFrontController()->getAction()->getFullActionName();?> /* this identifier value will change as per page.so echo this variable so you will get page identifier on all pages*/
for cart page :
if($pageIdentifier == 'checkout_cart_index'){echo 'this is cart page';}
for onepage checkout page :
if($pageIdentifier == 'aw_onestepcheckout_index_index'){echo 'this is checkout page';}
for order sucess page :
if($pageIdentifier == 'checkout_onepage_success'){echo 'this is sucess page';}
using this code you can get other pages identity and use as per your need.
Hope this will work.

Show content if child of a specific page

I am building a website in WordPress and have a set of photos that display along the top of the page (in the background) and have them to where the set of photos can change depending on where the visitor is on the website. For example, if they are looking at the FAQ page, then photos pertaining to asking questions are shown. If they are looking at the news page, then photos pertaining to news are shown. The code I have works great, however, I'd like to now show photos based on the parent of the page they are on; for instance, if they are looking at a child page under a parent.
Here's my code as it stands now:
<?php if ( is_front_page() ) { include'media/home.php'; }
elseif ( is_404() ) { include'media/404s.php'; }
elseif ( is_page('news') ) { include'media/home.php'; }
elseif ( is_page('faqs') ) { include'media/faqs.php'; }
elseif ( is_category('africa-2') ) { include'media/faqs.php'; }
else { include'media/general.php'; }
?>
How can I tell WordPress, I want it to show a certain php file if it is a parent page and all of it's children?
If you're in the loop you can just use
if( is_page('faqs') && $post->post_parent ){
//include template here
}
If you're outside the loop you'll need to include global $post before the conditional.
global $post
You can reference this link http://codex.wordpress.org/Conditional_Tags#Testing_for_sub-Pages

Categories