Hi,
You can make this change in loop.php file and add this code: http://screencast.com/t/3e4ogIsjrP
$adcounter = 0; add this at the top of the loop like in the screenshot.
$adcounter++;
if (is_category() && ($adcounter == 2)) {
echo do_shortcode('[td_ad_box spot_id="custom_ad_1"]');
}
.. and this at the bottom like shown in the screenshot.
Should work like this: http://screencast.com/t/RerPylFiEqI
Make sure you set the ad to show up on category pages after and exact number of posts if you are using an layout which is displaying two posts or 3 posts depending of page layout.
Thanks
Heya,
First of all, I’m far from the most brilliant guy on tagDiv. If I were, we wouldn’t have spent have a dozen posts correcting my tiny mistakes 😉 I’ll give that title to Chris to avoid favouritism among the actual staff…
Your ideal setup definitely requires some custom work that I don’t have time to provide at the moment. I would go to http://studio.envato.com, as tagDiv recommends — or you could do some learning, just like I did, and do it yourself 😀 But I will make a few comments:
Having content in these tabs that differs from post to post means you’ll either need to make extensive use of custom fields, or you could use Visual Composer settings to build the post itself. The question is what are you using the regular post content for? A comment on the phone, for example?
The first option would mean that you’d insert code similar to what I’ve been giving you, and have it appear on every template, using custom fields to determine the content. For example, as you probably know, ACF has a WYSIWYG editor field that you could use for your review. The buy now would not be as easy to automate through such a field, in my opinion (but you may already have a solution and just be looking for how to use tabs for it?).
The second option is that you’d construct these posts in the editor itself using Visual Composer, and then perhaps use custom shortcodes to display the content of your fields.
Or a real developer might suggest some much more sensible solution. :p
But I will give you one last thing, namely a basic tweak of my above code just for your “Features” tab.
The idea is the same. You’re opening up a vc_tabs, you’re opening up a tab, and then you’re looping through features-related fields. It could look like this, with lots of extra comments and line breaks to make it clear for you:
// Update this list using the same format for all the field names you want
$field_names = ['2g_network', '3g_network'];
// Set up tabs
$to_echo = '[vc_row][vc_column width="1/1"][vc_tabs]';
// Set up features tab
$to_echo .= '[vc_tab title="Features" tab_id="features"]';
// Begin a list
$to_echo .= '<ul class="features_list">';
// Loop through the fields
foreach ($field_names as $field_name) {
$data = get_field_object($field_name);
// Check if we have a value and set to a default if not
if ($data['value']) {
$value = $data['value'];
} else {
$value = 'No information on record.';
}
$to_echo .= '<li>' . '<span class="features_label">' . $data["label"] . ': </span>';
$to_echo .= '<span class="features_value">' . $value . '</span></li>';
}
// Close the list
$to_echo .= '</ul>';
// Close the tab
$to_echo .= '[/vc_tab]';
// Close the tab group etc.
$to_echo .= '[/vc_tabs][/vc_column][/vc_row]';
// We have to filter the whole string to make WP interpret the shortcodes
$to_echo = wpb_js_remove_wpautop($to_echo);
// Output
echo $to_echo;
My note above about only needing to change $field_names applies to this as well.
If you were going to put other tabs in, you would modify the lines that open and close the tab groups, and use those in a similar way. I realize that this is just a simple list and not a table like you wanted — more research would be needed for me to construct a way of getting the label of the field group and such…
Hope that helps. I do think what you need isn’t just “support” but custom work, although it will be fantastic if you can figure the rest out by research, trial and error.
Best of luck!
In the following files: loop-single.php, loop-single-1.php, single_template_2.php, single_template_3.php, single_template_4.php, single_template_5.php
Replace
<?php echo $td_mod_single->get_author();?>
with
<?php echo '<a itemprop="author" href="' . get_author_posts_url($post->post_author) . '">' . get_the_author_meta('display_name', $post->post_author) . '</a>';?>
Hope that helps 🙂
Hi,
You can use this code in loop.php file like this: http://screencast.com/t/lI3oL0TV0O6
Replace the ‘207’ with your category ID in which you would want the block to be showed. Also use the do_shortcode() function to add the block widget as you like, just replace the short-code from my example with your own.
Hope this helps!
Here is the code I used:
if (is_category('226')) {
echo do_shortcode('[vc_row][vc_column width="1/1"][td_block9 sort="random_posts" limit="5"][/vc_column][/vc_row]');
}
Thanks
Yes, just checked your file and the problem is in the context — you forgot to wrap the new code in a <?php> tag. Hence it’s being treated as HTML. Your whole file should look like this:
<?php
/**
* The single post loop for post template 1
**/
if (have_posts()) {
the_post();
$td_mod_single = new td_module_1($post);
//show the breadcrumb
if (get_post_type($post) == 'post') {
echo td_page_generator::get_single_breadcrumbs($td_mod_single->title);
} else {
echo td_page_generator::get_page_breadcrumbs($td_mod_single->title);
}
?>
<article id="post-<?php echo $td_mod_single->post->ID;?>" class="<?php echo join(' ', get_post_class());?>" <?php echo $td_mod_single->get_item_scope();?>>
<header>
<?php echo $td_mod_single->get_title();?>
<div class="meta-info">
<?php echo $td_mod_single->get_category();?>
<?php //echo $td_mod_single->get_author();?>
<?php echo $td_mod_single->get_date(false);?>
<?php echo $td_mod_single->get_commentsAndViews();?>
</div>
</header>
<?php if (!empty($td_mod_single->td_post_theme_settings['td_subtitle'])) { ?>
<p class="td-sub-title"><?php echo $td_mod_single->td_post_theme_settings['td_subtitle'];?></p>
<?php } ?>
<?php
// override the default featured image by the templates (single.php and home.php/index.php - blog loop)
if (!empty(td_global::$load_featured_img_from_template)) {
echo $td_mod_single->get_image(td_global::$load_featured_img_from_template);
} else {
echo $td_mod_single->get_image('art-big-1col');
}
?>
<div class="td-post-text-content">
<?php echo $td_mod_single->get_content();?>
<?php
// Set up your row, column, and tabs element
$to_echo = '[vc_row][vc_column width="1/1"][vc_tabs]';
// Simplest possible example of getting ACF data, sub in yours
$data_1 = get_field('2g_network');
$data_2 = get_field('3g_network');
// Repeat these lines for each tab, making sure each tab has a unique id
$to_echo .= '[vc_tab title="The first tab" tab_id="tab_1"]';
$to_echo .= $data_1;
$to_echo .= '[/vc_tab]';
$to_echo .= '[vc_tab title="The second tab" tab_id="tab_2"]';
$to_echo .= $data_2;
$to_echo .= '[/vc_tab]';
// (You could wrap each block in an if to skip a tab if the data is empty)
// When you have all your tabs, close the elements
$to_echo .= '[/vc_tabs][/vc_column][/vc_row]';
// We have to filter the whole string to make WP interpret the shortcodes
$to_echo = wpb_js_remove_wpautop($to_echo);
// Do whatever
echo $to_echo;
?>
</div>
<div class="clearfix"></div>
<footer>
<?php echo $td_mod_single->get_post_pagination();?>
<?php echo $td_mod_single->get_review();?>
<?php echo $td_mod_single->get_source_and_via();?>
<?php echo $td_mod_single->get_social_sharing();?>
<?php echo $td_mod_single->get_social_like_tweet();?>
<?php echo $td_mod_single->get_next_prev_posts();?>
<?php echo $td_mod_single->get_author_box();?>
<?php echo $td_mod_single->get_item_scope_meta();?>
</footer>
</article> <!-- /.post -->
<?php echo $td_mod_single->related_posts();?>
<?php
} else {
//no posts
echo td_page_generator::no_posts();
}?>
Hi,
I’m not sure if I understood right what you want, I believe you want that the post author to appear after the date of the post and not at the bottom of the posts where the author box it’s positioned. If this is way you want it please make sure you remove the comment from the loop-single.php and loop-single-1.php files. Edit each file and remove the two slashes “//” like this: http://screencast.com/t/VLf3DkCMw
For the other post style 2/3/4/5 you will have to edit the single_template_2/3/4/5.php files and remove the slashes “//”, like this: http://screencast.com/t/T8R4KFZhhnZl
If you want the author to appear after the date switch the line between them, like this: http://screencast.com/t/VJeSEWnwM4
Then go to td_module.php file and do this: http://screencast.com/t/kIj3H0yWMW like this: http://screencast.com/t/ZzzuRQLpfGG
After this add this custom css in theme panel > custom css field:
.single header .meta-info time {
font-style: normal !important;
margin-right: 0px !important;
}
You should get this result: http://screencast.com/t/58xJxjP1pDUW
You can disable the “author box” on post pages from theme panel > post settings: http://screencast.com/t/GM3BPolH
Hope this helps!
Thanks
The edits are good but they only apply to one of many possible templates your posts can have. Do the exact same code edit (uncommenting the byline) in each of the following files:
loop-single.php, loop-single-1.php, single_template_2.php, single_template_3.php, single_template_4.php, single_template_5.php
And if you want, a similar edit for each of these files in includes/modules (the modules display posts in blocks and archive pages mainly):
td_module_1.php, td_module_2.php, td_module_3.php, td_module_4.php, td_module_5.php, td_module_6.php, td_module_8.php, td_module_9.php, td_module_aj_search.php, and td_module_search.php (if it isn’t already uncommented in that last one).
Happy editing!
I tried to implement as per your instructions. Please check this screenshot it was with the_field.
I don’t know where i am making a mistake. I again changed the code to get_field and it still remains the same. Here you can see it.
Here is the full code of loop-single-1.php in which i am inserting.
<?php
/**
* The single post loop for post template 1
**/
if (have_posts()) {
the_post();
$td_mod_single = new td_module_1($post);
//show the breadcrumb
if (get_post_type($post) == 'post') {
echo td_page_generator::get_single_breadcrumbs($td_mod_single->title);
} else {
echo td_page_generator::get_page_breadcrumbs($td_mod_single->title);
}
?>
<article id="post-<?php echo $td_mod_single->post->ID;?>" class="<?php echo join(' ', get_post_class());?>" <?php echo $td_mod_single->get_item_scope();?>>
<header>
<?php echo $td_mod_single->get_title();?>
<div class="meta-info">
<?php echo $td_mod_single->get_category();?>
<?php //echo $td_mod_single->get_author();?>
<?php echo $td_mod_single->get_date(false);?>
<?php echo $td_mod_single->get_commentsAndViews();?>
</div>
</header>
<?php if (!empty($td_mod_single->td_post_theme_settings['td_subtitle'])) { ?>
<p class="td-sub-title"><?php echo $td_mod_single->td_post_theme_settings['td_subtitle'];?></p>
<?php } ?>
<?php
// override the default featured image by the templates (single.php and home.php/index.php - blog loop)
if (!empty(td_global::$load_featured_img_from_template)) {
echo $td_mod_single->get_image(td_global::$load_featured_img_from_template);
} else {
echo $td_mod_single->get_image('art-big-1col');
}
?>
<div class="td-post-text-content">
<?php echo $td_mod_single->get_content();?>
// Set up your row, column, and tabs element
$to_echo = '[vc_row][vc_column width="1/1"][vc_tabs]';
// Simplest possible example of getting ACF data, sub in yours
$data_1 = get_field('2g_network');
$data_2 = get_field('3g_network');
// Repeat these lines for each tab, making sure each tab has a unique id
$to_echo .= '[vc_tab title="The first tab" tab_id="tab_1"];
$to_echo .= $data_1;
$to_echo .= '[/vc_tab]';
$to_echo .= '[vc_tab title="The second tab" tab_id="tab_2"];
$to_echo .= $data_2;
$to_echo .= '[/vc_tab]';
// (You could wrap each block in an if to skip a tab if the data is empty)
// When you have all your tabs, close the elements
$to_echo .= '[/vc_tabs][/vc_column][/vc_row]';
// We have to filter the whole string to make WP interpret the shortcodes
$to_echo = wpb_js_remove_wpautop($to_echo);
// Do whatever
echo $to_echo;
</div>
<div class="clearfix"></div>
<footer>
<?php echo $td_mod_single->get_post_pagination();?>
<?php echo $td_mod_single->get_review();?>
<?php echo $td_mod_single->get_source_and_via();?>
<?php echo $td_mod_single->get_social_sharing();?>
<?php echo $td_mod_single->get_social_like_tweet();?>
<?php echo $td_mod_single->get_next_prev_posts();?>
<?php echo $td_mod_single->get_author_box();?>
<?php echo $td_mod_single->get_item_scope_meta();?>
</footer>
</article> <!-- /.post -->
<?php echo $td_mod_single->related_posts();?>
<?php
} else {
//no posts
echo td_page_generator::no_posts();
}?>
I think the code is not executing. Am i placing it in the wrong way?
For problem 2, if you want, you can hack it out of the single template files. What you would do is first make sure you have a child theme set up and activated. (You could do this in the Newspaper them itself, but it would not survive a theme update. Then again, hopefully an update will allow you to disable categories via the panel.)
Then, for each of the following files in the Newspaper theme folder:
loop-single.php, loop-single-1.php, single_template_2.php, single_template_3.php, single_template_4.php, single_template_5.php
Copy and paste them into your child theme folder.
In each one, find the line:
<?php echo $td_mod_single->get_category();?>
and comment it out like this:
<?php // echo $td_mod_single->get_category();?>
Upload the files to your site. Your template files will no longer add the category element to your posts.
Happy editing and hope someone else stops by to help with the other problems!
i would like to change the default “No posts to display”
I found this in loop.php echo td_page_generator::no_posts(); but I am not sure how to follow
thanks
Please can you add the ‘category__not_in’ field for each component because I don’t want to overwrite your stuff each time.
Regards,
ex:
class td_slide extends td_block {
function __construct() {
$this->block_id = 'td_slide';
add_shortcode('td_slide', array($this, 'render'));
}
function render($atts){
$this->block_uid = td_global::td_generate_unique_id(); //update unique id on each render
extract(shortcode_atts(
array(
'limit' => 5,
'sort' => '',
'category_id' => '',
'category_ids' => '',
'category__not_in' => '',
....
function get_map () {
//get the generic filter array
$generic_filter_array = td_generic_filter_array::get_array();
//add custom filter fields to generic filter array
array_push ($generic_filter_array,
+array(
+ "param_name" => "category__not_in",
+ "type" => "textfield",
+ "value" => '',
+ "heading" => "Exclude posts from categories id (, separated)",
+ "description" => "",
+ "holder" => "div",
+ "class" => ""
+),
In td_data_source
class td_data_source {
static $fake_loop_offset = 0; //used by the found row hook in templates to fix pagination. The blocks do not use this since we use custom pagination there.
/**
* converts a pagebuilde array to a wordpress query args array
* creates the $args array from shortcodes - used by the pagebuilde + widgets + by the metabox_to_args
* @param string $atts : the shortcode string
* @param string $paged : page number /1 or /2
* @return array
*/
static function shortcode_to_args($atts = '', $paged = '') {
extract(shortcode_atts(
array(
'category_ids' => '',
'category_id' => '',
+ 'category__not_in' => '',
...}
if (!empty($category__not_in)) {
$wp_query_args['category__not_in'] = explode(',', $category__not_in);
}
Hi,
Use the do_shortcode() function and add the shortcode of your custom block as you like into post template after the comments template, other than that you could modify the post template and add the code for the loop there and customize it, the theme was not designed that way so this needs custom work and you need to hire a developer to do that for you if you don’t know how because we cannot offer custom work.
Thanks
I didn’t edit the loop_single file but the td_module_blog in /includes/modules/module_modifier/.
I’m still running Newspaper v3.x and not v4 because I didn’t had time to update the theme. I’m running a high traffic site and still don’t have a staging site to update the theme to v4 without interupting traffic :p Anyway, I think the post pages in v4 are still generated by td_module_blog so you should give it a shot!
I don’t know about making custom fields with that plugin, I just followed tagDiv’s recomandations on using that plugin for creating additional custom fields.
When opening td_module_blog.php, look for the line (somewhere around line 600 in my version) that says:
if (empty($hideAuthor)) {
$buffy .= '<div class="author-box-wrap">';
$buffy .= '<a itemprop="author" href="' . get_author_posts_url($author_id) . '">' ;
$buffy .= get_avatar(get_the_author_meta('email', $author_id), '106');
$buffy .= '</a>';
and add and get_field('customfieldname')
Like this (notice i used ‘show_author’ as custom field name):
if (empty($hideAuthor) and get_field('show_author')) {
$buffy .= '<div class="author-box-wrap">';
$buffy .= '<a itemprop="author" href="' . get_author_posts_url($author_id) . '">' ;
$buffy .= get_avatar(get_the_author_meta('email', $author_id), '106');
$buffy .= '</a>';
Make sure your theme settings are set to show author. When the custom field for showing author is checked in a certain post the author box will show up. Hope this helps!
In a child theme, copy and edit the single_template_#.php that you’re using for your posts. (Note that for template 1, this is in loop-single-1.php instead.)
Near the top you will find a series of lines like this:
<div class="meta-info">
<?php echo $td_mod_single->get_category();?>
<?php //echo $td_mod_single->get_author();?>
<?php echo $td_mod_single->get_date(false);?>
<?php echo $td_mod_single->get_commentsAndViews();?>
</div>
Try turning them into something like this:
<div class="meta-info">
<?php echo $td_mod_single->get_category();?>
<?php echo $td_mod_single->get_date(false);?>
<?php echo $td_mod_single->get_date(false);?>
<?php echo get_avatar($post->post_author, '40');?>
<?php echo $td_mod_single->get_author();?>
<?php echo $td_mod_single->get_commentsAndViews();?>
</div>
Notes:
1. If you don’t have a child theme yet, you can test this in the theme editor by changing Newspaper’s own files, but make sure you backup the file
2. ’40’ is 40px, the width and height of the avatar image. Change to whatever you want
3. I haven’t tested the get_avatar function with an author ID — in the tagDiv files the parameter is the user email. If it doesn’t load the avatar, replace $post->post_author with get_user_by('id', $post->post_author)->user_email or something similar
4. You can style the avatar and user name to be right aligned by looking at the comments and views css and imitating that. Try echoing a <div> with a class like my_author_meta around those two echo statements, and then style that in the custom CSS panel
Just a thought and not tested. Let me know how it works.
Hm. Not sure; I’d likely use the page builder to make a “page” then set that as your home page, as that also allows you to create custom sidebar for homepage, but keep “blog timeline” layout, but also to add “sections” where you want like a custom box top of page above the new posts where you can put something custom with h1 tag; or even a section below latest posts where you put something with h2 tags. That would be simpler than hacking the home page template where you’d need to drop stuff in above and below the page loops, which are kind of complex due to the various theme options.
If you want to hard code the number of posts shown on a category page and not use the built in function of wordpress, you “might” be able to use visual composer for that but I’ve not done that, or you’d need to modify the category template and manually specify the loop (if you have no idea how to do that, you might need to hire a developer).
Obviously if you only want to show 10 items on the category pages, you would set that from the wordpresss > reading function you’ve already used. 20 is a common number to use, however, and works fine on most websites. Some people do less, some people do more. If your main audience is mobile, obviously 10 is a good number.
Since that function impacts the category pages, you’d then use the visual composer to layout your home page and not be impacted by the “10” settings.
In other words, easier to layout the home page with the theme features, than hack the template for the category pages.
Hi Team,
I have got some Taxonomies in my theme and I was able to display them on single post pages by editing the single-loop file.
How do I display them on the home page? I’m using a mix of different blocks on the home page.
Also where do I find the code related to the post settings like Source name, Source url etc. I want to edit/add new fields and use them both on Single posts as well as on the home page.
Just pointing me to the files names is good enough and any help above that would be much appreciated 🙂
Thanks in adv.
Sam.
Hey, so basic question. I know we can simply add the same share code from loop-single.php but what .php page do we customize to add the share to the posts images (when the image is clicked and it goes to that individual image url). I am also looking to insert a Previous and Next navigation below the individual image post if possible.
Hi,
1. You could move this lines in loop-single.php file like this: http://screencast.com/t/NCVEbleIM8T but then the featured image on all post pages will move to bottom of the page.
Other solution would be to insert the video directly in the post by pasting the video url in your post content where you want it to appear and set the post type to gallery post and also add the video in the featured video field.
2. I’m not sure I understand what are you referring too, on pages/blocks the featured image thumb for video posts should look like this http://screencast.com/t/Gj9GAnhVm and on default post pages like this: http://screencast.com/t/z8ubx97Zl8F in the second case it’s a video not an image but the image should look the same.
Can you please send me a screenshot or a link to your site see this issue?
Thanks
-
This reply was modified 12 years by
Lucian.
Let’s assume you’re wanting to hide a particular category from the home page.
1. Open up the honmepage “page”.
2. Scroll down past main page information down to the sectioned entitled “Home Page Loop Filter”.
3. You should see “Category Filter” – leave that on All categories.
4. Below this field, you should see “Multiple categories filter:”. You’ll need to list the numbers of all the categories you DO want to show – just exclude the ones you don’t want to see. eg; Say you have 20 categories, and you want to show 19 of them; you want to exclude Category 20….. You’d list 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19…..
You can use this same methodology to exclude certain categories from the various widgets,etc.
If you’re wondering how you can find out a category number from its name, there are a few ways;
1. You can go check out the wp_terms table.
2. You can write your own code to reveal it
3. From the admin panel, go to Posts > catgeories. Mouse over each of the categories, and the URL will have an attribute with a number in it – this number is the associated category number.
NOTE: In my example i listed 1,2,3,..19… In reality, your first Category may well start at 3.
I hope that helps.
hi,
In version 4.0 we have added posts templates : http://screencast.com/t/QhAcLBYffKC
and now we have 6 loop-singe files, each one used to display a post template.
http://screencast.com/t/yLUPBJkYK
loop-single.php is used to display the default template.
————————————–
Now about author box, are you referring to this one: http://screencast.com/t/zP7ivobP
I don’t think you can do this for user Administrator, but is possible for other users.
In order to remove the box just for the some users you need to know their id’s.
take the user id from here: http://screencast.com/t/qMEEZyYuLq
then modify each loop-single .php file -> http://screencast.com/t/EjN5yfCE
then in the td_module_blog.php -> function get_author_box : http://screencast.com/t/wEAc5wbE23
is not easy but can be made.
hope this help.
Thanks for you message.
Radu A.
Offset is set in the visual composer for each module I believe.
You could also modify templates per the WordPress codex info, for the loop and use the offset function as found here:
http://codex.wordpress.org/Template_Tags/get_posts
Hi,
You can try this css to style post pagination:
.single .page-nav-post {
text-align: center;
}
.single .page-nav span {
min-width: 50px;
}
This will center the post pagination and make it wider, you can change the values as you want. Removing the numbers in between the first and last page it’s not an easy task and need custom work, you can try it yourself if you want.
About the pagination above the image, I gave you the solution to add the ad box, and place it after the content in the loop-single.php file like this: http://screencast.com/t/uEBPCkfawmC
Make sure you have remove the article bottom ad from theme panel also.
Should get this result: http://screencast.com/t/BOVvHX5K
Thanks
What is the article_bottom_ad? I tried the below and no luck.
<?php echo do_shortcode(‘[td_ad_box spot_id=”article_bottom_ad”]’); ?>
This right here is basically what im trying to accomplish:
http://screencast.com/t/r9hhfebNt7d
Moving the 728×90 below <!–nextpage–> shortcode, center pagination, removing the numbers in between the first and last page but keeping the amount there and create the buttons larger. And inserting the pagination above the image.
I would have imagined the ad code would be in loop-single, or if there is a php echo code that can be placed inside there.
*For the time being, I manually placed the ad code in loop-single.php and removed the article_bottom_ad.*
Hi,
You can try adding it using the do_shortcode function for custom ad box and add it like this in the loop-single.php file: http://screencast.com/t/QexjAdJiBuVZ
Here is the code you need:
<?php echo do_shortcode('[td_ad_box spot_id="custom_ad_3"]'); ?>
Also add your ad code inside the Custom ad 3 like this: http://screencast.com/t/IdQeUAdg
This way you have to remove the article bottom ad and the custom ad will remain under the pagination and above the prev/next post.
Use this css to arange it:
.single .td-a-rec-id-custom_ad_3 {
margin-top: -20px !important;
margin-bottom: 20px !important;
}
Use this class to style the post pagination:
.page-nav-post {
padding: 0px;
margin-bottom: 42px;
}
like this: http://screencast.com/t/OZmQAGbb
Hope this helps!
Thanks