How to reuse the same widgets in different wordpress pages - wordpress

I have to the following page which has a widget called press as you can see in the screenshot
I had created another page (manually and by cloning pulgin) and I can't reuse the same widget in the new page.
Any ideas how can I do that?

you can add sidebar in particular page template
Ex. sidebar slug name : "left-sidebar"
<?php if ( is_active_sidebar( 'left-sidebar' ) ) : ?>
<?php dynamic_sidebar( 'left-sidebar' ); ?>
<?php endif; ?>
Or
you can use below plugin
https://wordpress.org/plugins/display-widgets/
Page template section screenshot
For Ex. About Us Template

Related

Angular + WordPress

I have a ticket sales form written in Angular. How can I insert this form on the main page of Wordpress site? May be with usingthe tag iframe or can there be better solutions for this task? Thank you for attention!
I think a best solution to this is to create a new page template (you can google it to get more accurate info), see what is page templates here.
Basically, you will create a new file on your theme root, with the prefix page-, e.g: page-tickets.php. And then the very first thing that must appear on your page is a comment,like this: // Template Name: Tickets Page. Your page will be something like this:
<?php
// Template Name: Tickets Page
get_header();
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
// Angular + Html codes here!
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
<script>angular and js imports</script>
<?php get_footer(); ?>
With that, when you will create a new page in Pages -> New (or edit), in the right bottom side will be available an option to you to choose a page template, like this:
That's all, I hope it helps you.

How to repeat ACF Flexible Content on single pages?

Disclaimer: If you have never used ACF Flexible Content to build a site, please reserve the hate and all that - looking just for help.
I'm creating a website that's 100% modular, done with Flexible Content.
I have Pages such as:
Home, About, Services, Blog, Portfolio, Contact
All of those pages styled using Flexible Content, these are PAGES.
I have created a custom field for Services and Portfolio, and I used WP Query to display each individal item. These are CUSTOM fields. Show this field group if post type to Services. Not a page.
So when you click it, what happens you go to single-[custom-post-type].php, however I just have single.php to keep it dynamic, which works.
The problem lays that when I have showed the flexible content page templates in the Services or Portfolio, and I add few items, I need go to every single item and set the layout.
How can I do so the layout stays all the same in Service or Portfolio custom field?
Firstly create your ACF Master block, for example, a testimonial section, this would have the repeater fields inside the block etc. In this example, we will call it Testimonial Master.
Then Create another Flexible Content Field Called Testimonial Block with a checkbox that you check to display or hide.
You will now populate Testimonial Master on your selected Parent Page or on an Options page. You then should add the Testimonial Block to any page you are looking to have that block appear on.
You will then went to check that the Testimonial Block is on the page, if it is on the page then you will check if Testimonial Master has a value if it has a value then you can pull in the values from Testimonial Master.
<?php
if( have_rows('page_structure') ):
while ( have_rows('page_structure') ) :
the_row();
if( get_row_layout() == 'testimonial_block' ):
if( get_sub_field('testimonial_block_toggle') == 'show' ):?>
<div class="testimonials">
<?php the_sub_field('testimonial_master_title', 1); ?>
</div>
<?php endif;
endif;
endwhile;
endif;
?>
The "1" is the page ID, use this if you have populated the field on a master page. Or if you are using the ACF Options Page plugin change the "1" to "'options'".
Here is some further documentation on getting values from other posts including that of repeater fields.
https://www.advancedcustomfields.com/resources/how-to-get-values-from-another-post/
Edit: Custom Header as per your example
Make a custom header file and add your code for that header block.
Now make an advanced custom field for a text area. For example header_text_block, set it to a WYSIWYG editor.
Now in your code just use:
<?php the_field('header_text_block');?>
This will then use the exact same header on every page you pull it into, however it will let you edit the text individually for each page.
Edit: Example of what this code looks like and does
Also I think you are very confused, there will only be 1 php/html file? you could use page.php.
Here's an example of what I am saying, 1 php file:
<?php if( have_rows('page_structure') ):
while ( have_rows('page_structure') ) : the_row();
if( get_row_layout() == 'page_featured' ):
$image = get_sub_field('page_featured_image');
if( !empty($image) ):?>
<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>">
<?php endif;
endif;
if( get_row_layout() == 'page_breadcrumbs' ):
if( !in_array( 'hide', get_sub_field('page_breadcrumbs_hide') ) ):?>
<?php if ( function_exists('yoast_breadcrumb') ) {yoast_breadcrumb('<p id="breadcrumbs">','</p>');}?>
<?php else :
endif;
endif;
endwhile;
endif;
?>
This then looks like this on the page editor:
You can then edit each section as you please and also drag and drop sections where you want them which enables easy split testing.
All the styling will be the same, just you can change the content and if you wanted you could add the ability to alter stylings pretty easily. And it only uses 1 PHP file for the template.

Cant' Grab WordPress Built-in Posts Through Loop

Using WordPress 3.7.1 I am trying to display all Regular Post on my created page lest say TestPage. Here are the steps I took to do this:
1- Generate a Custom Page Template called:Test Page and loaded by following code
2- Generate a Page Called TestPage based on Test Page Template
after updating the page I am not getting any of Post on the page while I have already generated some!
<?php
/*
Template Name: Test Page
*/
?>
<?php get_header(); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title() ;?></h1>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p>Sorry, this page does not exist</p>
<?php endif; ?>
<?php get_footer(); ?>
he abouve code actually is loading the page whit title and content of the TestPage and not by Posts!Can you please let me know why this is happening?
You must understand the difference between post and page.
A page is associated with a template. Through code, you can lists posts or other pages using this page /template.
The above code will only display the Page data
You don't want to create many pages using the same tempalte in order to show different data with the same tempalte. Instead you create posts and give them a category.
Then you can fetch these posts and display them in the same way asthe test-page.
You can either use get_posts or wp_get_recent_posts.
Or, if you really want to list pages, use wp_list_pages.
Besides that, you should look at http://codex.wordpress.org/Pages and http://codex.wordpress.org/Posts

How to retrieve all custom posts from all the categories in portfolio

I have created custom post type portfolio in wordpress. I have created categories like web-design, logo design, e-commerce, photography... etc. I have retrieved all these category as the navigation menu in portfolio template file (assigned to the portfolio page). Now I want there should be a link(view all) in the navigation menu which will retrieve all the posts from all the categories in portfolio. Basically I want a way for making default category which will retrieve all the posts. Can anybody please help me!!!
So, basically, you want to create a Custom Post Type Archive page.
A way to achieve this, as explained at WPBeginner.com, is like the following:
Create a custom page template (the PHP file could have any name you want) and Add the Template Name comment at the beginning of the file:
<?php /* Template Name: Custom Post Type Archive */ ?>
Create a custom loop:
<?php
/* Template Name: Custom Post Type Archive */
get_header();
?>
<?php
global $query_string;
query_posts($query_string . "post_type={YOUR-CUSTOM-POST-TYPE}&post_status=publish&posts_per_page=10");
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
?>
<h2><?php the_title(); ?></h2>
<?php the_excerpt(); ?>
<?php
endwhile;
endif;
?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('Previous entries') ?></div>
<div class="alignright"><?php previous_posts_link('Next entries') ?></div>
</div>
<?php wp_reset_query(); ?>
<?php get_sidebar(); ?>
<?php get_footer();?>
Create a new page and select the template you just created in the Page Attributes box
You should be able to use the archive page template to list them all then. Try going to http://yourdomain.com/portfolio and see if that brings it up. You will need to have enabled archives for the post type when you created it though. Look for 'has_archive' => true, if you created the post type manually by dropping in the code in your functions.php file. If you see that, but its set to "false", you'll need to change it to true.
You could also create a custom archive template for this post type if you wanted to. If you create a new file in your theme directory called archive-portfolio.php and then put a custom loop in there the post type will automatically target that template file when accessing the post type archive.
Then to link from your nav menu to this archive, just create a custom menu item in your menu editor with the url http://yourdomain.com/portfolio. You won't need to create any sort of "default" category if you take advantage of the post type archives.
Let me know if you have any other questions.

wordpress conditional statement for home page

I am developing a wordpress blog theme, which shows the posts on the homepage. I am trying to show some text ONLY on the homepage, and not on page 2,3 ,4 and so on of the blog posts. The code below shows the text on all blog pages:
<?php
if (is_front_page()) {
?><p>TEST FRONT PAGE</p>
<?php
} ?>
How do I show this ONLY on the front home page (page 1, not pages after 1)?
ANSWER FOUND IN COMMENT BELOW
Instead of declaring an additional variable and checking it you can access the global in wp_query with is_paged.
<?php if (is_home() && !is_paged()) : ?>
Your front page content.
<?php endif; ?>
Or if you have a static post as the front page with its own sub pages you can use:
<?php if (is_front_page() && !is_paged()) : ?>
Your static front page content.
<?php endif; ?>
To target just the first page of the static post.

Resources